Reinforcements via Transport "Help"!

Information and discussion for custom maps and mods.
Post Reply
Narcoleptic
Posts: 19
Joined: Fri Nov 20, 2015 7:40 am

Reinforcements via Transport "Help"!

Post by Narcoleptic »

Hey everyone. I'm having trouble with Lua and "Reinforcements.ReinforceWithTransport" Just can't make it work. I tried to replicate conditions from other RA missions but without success. Game crashes with exception.log "Collection was modified after the enumerator was instantiated". I'm not enterily sure what this error means. Collection is been modfied while its being used?

Somebody can explain to me how to solve this or why its failing? Or atleast point me in the right direction towards a solution?

Here is the code. SquadInsertion = function() is the one giving me troubles:

Code: Select all

if Map.Difficulty == "Easy" then
    SpyType = "spy"
    InfiltratedSquad = { "medi", "e3.defendstance", "e3.defendstance", "e1.defendstance", "e1.defendstance" }
    InsertionSquad = { "medi", "e3.defendstance", "e3.defendstance", "e1.defendstance", "e1.defendstance" }
elseif Map.Difficulty == "Normal" then
	SpyType = "spy"
    InfiltratedSquad = { "medi", "e3.defendstance", "e3.defendstance", "e1.defendstance", "e1.defendstance" }
    InsertionSquad = { "medi", "e3.defendstance", "e3.defendstance", "e1.defendstance", "e1.defendstance" }
else 
    SpyType = "spy.unarmed"
    InfiltratedSquad = { "e3.defendstance", "e3.defendstance", "e1.defendstance", "e1.defendstance" }
    InsertionSquad = { "medi", "e3.defendstance", "e3.defendstance", "e1.defendstance", "e1.defendstance" }
end



TranPath = { TranInsertion.Location, Flare.Location }
TransInsertionType = "tran.insertion"
ObjSams = {ObjSam1, ObjSam2, ObjSam3}
PatrolA = {PatrolA00, PatrolA01, PatrolA02, PatrolA03}
PatrolB = {PatrolB00, PatrolB01, PatrolB02}
PatrolC = {PatrolC00, PatrolC01, PatrolC02}
PatrolAPath = { PatrolAWay3.Location, PatrolAWay1.Location, PatrolAWay2.Location, PatrolAWay1.Location }
PatrolBPath = { PatrolBWay1.Location, PatrolBWay2.Location }
PatrolCPath = { PatrolCWay1.Location, PatrolCWay2.Location }
InfiltrationPoint = { InfiltrationSpawn.Location, InfiltrationTarget.Location }
Convoy = {"truk.mission", "truk.mission"}
ConvoyPathA = { ConvoyStart.Location, ConvoyWay01.Location, ConvoyWay02.Location, ConvoyEndA.Location}
ConvoyPathB = { ConvoyStart.Location, ConvoyWay01.Location, ConvoyWay02.Location, ConvoyEndB.Location}
ConvoyPathC = { ConvoyStart.Location, ConvoyWay01.Location, ConvoyWay02.Location, ConvoyEndC.Location}
AlliedConvoy = {"truk.mission"}
AlliedConvoyPath = { ConvoyStart.Location, InfiltrationSpawn.Location}

PowerSupply = 
{ 
    BaseAPower00, BaseAPower01, BaseAPower02, BaseAPower03, BaseBPower00, BaseBPower01, 
    BaseBPower02, BaseCPower00, BaseCPower01, BaseCPower02, BaseCPower03, 
    MainBasePower02, MainBasePower03, MainBasePower04, MainBasePower04, MainBasePower05, 
    MainBasePower06, MainBasePower07, MainBasePower08, MainBasePower09 
}

SetupAlliedUnits = function()
	
    Spy = Actor.Create(SpyType, true, { Owner = player, Location = EnglandSpy.Location, Facing = 128 })
	Camera.Position = Spy.CenterPosition
    Trigger.OnKilled(Spy, function() ussr.MarkCompletedObjective(ussrObj) end)
	
    Trigger.AfterDelay(DateTime.Seconds(1), function()
    
    end)
	
    Trigger.AfterDelay(DateTime.Seconds(1), function()USSR00.AttackMove(SpyReturn.Location) end)
    
	FirstCam = Actor.Create("camera", true, { Owner = player, Location = StartingCamera.Location })
    
end

SpyMustSurvive = function()

Trigger.OnKilled(Spy, function() ussr.MarkCompletedObjective(ussrObj) end) 


end

 Trigger.OnAllKilled(ObjSams, function()
		player.MarkCompletedObjective(destroySams)
        
    end)



Trigger.OnEnteredFootprint({ RadardomeVisionTrigger.Location }, function(a, id)
		if a.Owner == player then
            Actor.Create("camera", true, { Owner = player, Location = RadardomeVision.Location }) 
            Trigger.RemoveFootprintTrigger(id) end
    end)

InitTriggers = function()

	Trigger.OnInfiltrated(Radardome, function()
		Trigger.ClearAll(Spy)
        Actor.Create("camera.map", true, { Owner = player, Location = MapCamera1.Location }) 
        Actor.Create("camera.map", true, { Owner = player, Location = MapCamera2.Location })
        player.MarkCompletedObjective(infRadardome)
        SquadInsertion()
       
        Trigger.AfterDelay(DateTime.Seconds(1), function()
            Actor.Create("dome", true, { Owner = player, Location = OffmapRadar.Location })
            Actor.Create("powr", true, { Owner = player, Location = OffmapPower.Location })
            
        local TeslaCams = 
            { 
            Actor.Create("camera.tesla", true, { Owner = player, Location = TeslaCam00.Location }),
            Actor.Create("camera.tesla", true, { Owner = player, Location = TeslaCam01.Location }),
            Actor.Create("camera.tesla", true, { Owner = player, Location = TeslaCam02.Location }),
            Actor.Create("camera.tesla", true, { Owner = player, Location = TeslaCam03.Location }),
            Actor.Create("camera.tesla", true, { Owner = player, Location = TeslaCam04.Location })
            }
            
            Spy = Actor.Create(SpyType, true, { Owner = player, Location = Radardome.Location, Facing = 128  })
            Spy.DisguiseAsType("e1", ussr)
            Spy.Move(SpyReturn.Location)
           
        end)         
            
        Trigger.OnKilled(Spy, function() ussr.MarkCompletedObjective(ussrObj) end)
	end)
    
    
    SquadInsertion = function()
        local flare = Actor.Create("flare", true, { Owner = copter, Location = Flare.Location })
        Trigger.AfterDelay(DateTime.Seconds(21), flare.Destroy)

        Media.PlaySpeechNotification(player, "SignalFlare")
        
        ----Going nuts with this one
        ASDF = Reinforcements.ReinforceWithTransport(player, TransInsertionType, InsertionSquad, TranPath)[1]

        
    end
    
    
	Trigger.OnAllKilled(PowerSupply, function()
		player.MarkCompletedObjective(destroyPowerplants)
	end)



ActivatePatrols = function()
	GroupPatrol(PatrolA, PatrolAPath, DateTime.Seconds(2))
	GroupPatrol(PatrolB, PatrolBPath, DateTime.Seconds(2))
    GroupPatrol(PatrolC, PatrolCPath, DateTime.Seconds(5))

	local units = Map.ActorsInBox(Map.TopLeft, Map.BottomRight, function(self) return self.Owner == soviets and self.HasProperty("AutoTarget") end)
	Utils.Do(units, function(unit)
		unit.Stance = "Defend"
	end)
end

GroupPatrol = function(units, waypoints, delay)
	local i = 1
	local stop = false

	Utils.Do(units, function(unit)
		Trigger.OnIdle(unit, function()
			if stop then
				return
			end

			if unit.Location == waypoints[i] then
				local bool = Utils.All(units, function(actor) return actor.IsIdle end)

				if bool then
					stop = true

					i = i + 1
					if i > #waypoints then
						i = 1
					end

					Trigger.AfterDelay(delay, function() stop = false end)
				end
			else
				unit.AttackMove(waypoints[i])
			end
		end)
	end)
end


SendConvoy = function()
	Reinforcements.Reinforce(ussr, Convoy, ConvoyPathA, 20 )
    Reinforcements.Reinforce(ussr, Convoy, ConvoyPathB, 20 )
    Reinforcements.Reinforce(ussr, Convoy, ConvoyPathC, 20 )
    
    Trigger.AfterDelay(DateTime.Seconds(2), function()Reinforcements.Reinforce(ussrradar, AlliedConvoy, AlliedConvoyPath, 20) end)
 
    Trigger.AfterDelay(DateTime.Seconds(8), function()Reinforcements.Reinforce(player, InfiltratedSquad, InfiltrationPoint, 5) end)
end
	
	
end

InitObjectives = function()
	Trigger.OnObjectiveAdded(player, function(p, id)
		Media.DisplayMessage(p.GetObjectiveDescription(id), "New " .. string.lower(p.GetObjectiveType(id)) .. " objective")
	end)

	ussrObj = ussr.AddPrimaryObjective("Stop Allied infiltration.")
    infRadardome = player.AddPrimaryObjective("Infiltrate radar dome.")
	destroyPowerplants = player.AddPrimaryObjective("Destroy all power plants.")
	spySurvive = player.AddPrimaryObjective("Spy must survive.")
    destroyTruks = player.AddSecondaryObjective("Destroy convoy trucks.")
    destroySams = player.AddSecondaryObjective("Destroy all three sam sites nearby radar dome.")
	
	Trigger.OnObjectiveCompleted(player, function(p, id)
		Media.DisplayMessage(p.GetObjectiveDescription(id), "Objective completed")
	end)
	Trigger.OnObjectiveFailed(player, function(p, id)
		Media.DisplayMessage(p.GetObjectiveDescription(id), "Objective failed")
	end)
	
	Trigger.OnPlayerLost(player, function()
		Media.PlaySpeechNotification(player, "Lose")
	end)
	Trigger.OnPlayerWon(player, function()
		Media.PlaySpeechNotification(player, "Win")
	end)
end


	
WorldLoaded = function()
	player = Player.GetPlayer("ENGLAND")
	ussr = Player.GetPlayer("USSR")
	ussrradar = Player.GetPlayer("USSRRADAR")
	copter = Player.GetPlayer("COPTER")
    
	InitObjectives()
	InitTriggers()
	SendConvoy()
	Trigger.AfterDelay(DateTime.Seconds(3), ActivatePatrols)
	SetupAlliedUnits()

end

abcdefg30
Posts: 641
Joined: Mon Aug 18, 2014 6:00 pm

Post by abcdefg30 »

Weird, can you post the whole exception.log, please?

Narcoleptic
Posts: 19
Joined: Fri Nov 20, 2015 7:40 am

Post by Narcoleptic »

Here it is.

Code: Select all

Red Alert Mod at Version release-20150919
on map 3726bfb5b2f89fbd84e19699373f09078a8c9d24 (Blackout by Narcoleptic).
Operating System: Windows (Microsoft Windows NT 6.2.9200.0)
Runtime Version: .NET CLR 4.0.30319.42000
Exception of type `System.InvalidOperationException`: Collection was modified after the enumerator was instantiated.
   at System.ThrowHelper.ThrowInvalidOperationException(ExceptionResource resource)
   at System.Collections.Generic.SortedSet`1.Enumerator.MoveNext()
   at OpenRA.World.Tick()
   at OpenRA.Game.InnerLogicTick(OrderManager orderManager)
   at OpenRA.Game.LogicTick()
   at OpenRA.Game.Loop()
   at OpenRA.Game.Run()
   at OpenRA.Program.Run(String[] args)
   at OpenRA.Program.Main(String[] args)
Working on last stable release btw (2015/09/19)

abcdefg30
Posts: 641
Joined: Mon Aug 18, 2014 6:00 pm

Post by abcdefg30 »

So, I guess you missplaced an "end".
You start the "InitTriggers" function in line 79, but end it in line 183.

What happens when you remove the end from line 183 and add one in line 128?

Although I doubt this is the issue, I think we should start there (lua is sometimes silly with such stuff, so it could be the cause).

If the bug still persists, could you please upload the map?
That would make debugging easier, as I unfortunately can't get much information out of the exception log.

Narcoleptic
Posts: 19
Joined: Fri Nov 20, 2015 7:40 am

Post by Narcoleptic »

Changed it but error persists: "Collection was modified after the enumerator was instantiated"
I have no idea how to solve this one.

Here is the map.
Attachments
blackout.rar
(41.41 KiB) Downloaded 370 times

abcdefg30
Posts: 641
Joined: Mon Aug 18, 2014 6:00 pm

Post by abcdefg30 »

Ok, the crash seems to be fixed if you replace "SquadInsertion()" in line 86 by "Trigger.AfterDelay(0, SquadInsertion)".

PS: The map already looks nice, please notify me when you've finished it. :)

Narcoleptic
Posts: 19
Joined: Fri Nov 20, 2015 7:40 am

Post by Narcoleptic »

Thanks a lot! Working perfectly. :D Glad you like it. I'll upload the final .ver once a few tweaks.

Post Reply