From 42532efd8f87fba5c54446b6519afd4b944aac7d Mon Sep 17 00:00:00 2001 From: Oliver Brakmann Date: Thu, 30 Jan 2014 22:23:09 +0100 Subject: [PATCH] Replace Lua's for loops with Utils.Do/Team.Do Besides fitting in better with the OpenRA coding style, this also gets rid of some weird timing-related errors I have seen when creating teams with a larger number (6+) of members. (The script would just print 'Error: function' in Team.AddActorEventHandlers. Adding a strategically placed print statement fixed that. Replacing the original for loop with Team.Do did as well) --- mods/common/lua/team.lua | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/mods/common/lua/team.lua b/mods/common/lua/team.lua index 074e02c076..f0f9da15c8 100644 --- a/mods/common/lua/team.lua +++ b/mods/common/lua/team.lua @@ -12,7 +12,7 @@ Team.New = function(actors) end Team.AddActorEventHandlers = function(team) - for i, actor in ipairs(team.Actors) do + Team.Do(team, function(actor) Actor.OnKilled(actor, function() Team.InvokeHandlers(team.OnAnyKilled) @@ -23,13 +23,11 @@ Team.AddActorEventHandlers = function(team) Team.InvokeHandlers(team.OnAnyRemovedFromWorld) if not Team.AnyAreInWorld(team) then Team.InvokeHandlers(team.OnAllRemovedFromWorld) end end) - end + end) end Team.InvokeHandlers = function(event) - for i, handler in ipairs(event) do - handler() - end + Utils.Do(event, function(handler) handler() end) end Team.AllAreDead = function(team)