Page 1 of 1

recursion is not permitted on a give order to unit call?

Posted: 08 Dec 2010, 09:24
by smoth
LuaRules::RunCallIn: error = 2, UnitCreated, [string "LuaRules/Gadgets/grts_holdpsition.lua"]:30: GiveOrderToUnit() recursion is not permitted
stack traceback:
function gadget:GetInfo()
return {
name = "Hold postion gadget",
desc = "sets unit on creation to hold position",
author = "smoth",
date = "2010-09-23",
license = "pd",
layer = 300,
enabled = true
}
end

local holdGroup

if VFS.FileExists("LuaRules/Configs/holdposition.lua") then
holdGroup = VFS.Include("LuaRules/Configs/holdposition.lua")
else
error("missing file: LuaRules/Configs/holdposition.lua")
end
-- for K,V in pairs(holdGroup) do
-- Spring.Echo(K,V)
-- end

if (gadgetHandler:IsSyncedCode()) then

function gadget:UnitCreated(u, ud, team, builder)

if(holdGroup and holdGroup[UnitDefs[ud].name]) then
Spring.Echo(u, ud, team, builder)--
Spring.GiveOrderToUnit(u, CMD.MOVE_STATE, { 0 }, 0)
end
end

end
include file is just some defines for my unit list. so don't worry about that.

here is the issue, when I am in sandbox mode and say I place more that I am permitted say unit is restricted to 5 units and I order a commander to build 6, I get this error. I was wondering why it is seeming to believe i am making a recursive call on the units that are set to be built?

Repeatable error in sandbox commander mode of gundam rts(current release). Repeat steps: grab zeon commander line order >5 zakusnipers.

I do not really need a fix for this, I merely want to know why it seems to think I am trying recursion.

Re: recursion is not permitted on a give order to unit call?

Posted: 08 Dec 2010, 09:36
by knorke
I had a very similiar problem once and the answer is that Spring is just overly protective and thus does not permit some things.

Like creating units in UnitCreated() callin
or creating units in UnitDestroyed() callin or in your case GiveOrder.
(though infact that does work but it is somehow not clean because the same gadget that worked will fail in ie a mission made with the editor. I guess sandbox mode is maybe similiar to the misson stuff so that might cause it.)

Solution is to move stuff like that to GameFrame()

Re: recursion is not permitted on a give order to unit call?

Posted: 08 Dec 2010, 18:17
by smoth
knorke wrote:I had a very similiar problem once and the answer is that Spring is just overly protective and thus does not permit some things.
it is only triggered when i try to build more than I am allowed via unit restricted.
knorke wrote:Like creating units in UnitCreated() callin
or creating units in UnitDestroyed() callin
the former kinda makes sense the latter doesn't
knorke wrote: or in your case GiveOrder.
(though infact that does work but it is somehow not clean because the same gadget that worked will fail in ie a mission made with the editor. I guess sandbox mode is maybe similar to the mission stuff so that might cause it.)
sandbox mode is just a thing that disables resource costs and allows me to build any unit in the game with fly commander nothing special.
knorke wrote:Solution is to move stuff like that to GameFrame()
The purpose of my hold position code is to ensure snipers always start with hold position orders. Why would I move that into gameframe?

Re: recursion is not permitted on a give order to unit call?

Posted: 08 Dec 2010, 18:32
by knorke
it does not make sense but thats the way it is, i find it annoying too.
i made a unit called "trigger_meteorstorm" that does nothing but instally kill itself and is also invisible.
The space rocks gadget of CT detects the death of this "trigger unit" and causes a meteorite rain at its position. That way I made the meteors drop at a specified location in the CT Testmission.
And it was exactly the problem of "creating units in UnitDestroyed() callin" causing a recursion error. Moving the actual unit creation to GameFrame fixed it. Stupid, but whatchagonnado?
Unless the snipers shot the very moment they are spawned (is that even possible?), setting their fire state one frame later will not matter.

Re: recursion is not permitted on a give order to unit call?

Posted: 08 Dec 2010, 19:42
by smoth
just taht a less direct method seems like I am just doing bad code to dodge what may be a bug with the spring lua that should be fixed.

Re: recursion is not permitted on a give order to unit call?

Posted: 18 Dec 2010, 03:03
by bobthedinosaur
I am also running into this issue. Has any one requested a feature to the engine for a fix to this?

Re: recursion is not permitted on a give order to unit call?

Posted: 18 Dec 2010, 20:42
by SirMaverick
smoth wrote:
LuaRules::RunCallIn: error = 2, UnitCreated, [string "LuaRules/Gadgets/grts_holdpsition.lua"]:30: GiveOrderToUnit() recursion is not permitted
stack traceback:
Post full stacktrace next time. Or read it yourself.
here is the issue, when I am in sandbox mode and say I place more that I am permitted say unit is restricted to 5 units and I order a commander to build 6, I get this error. I was wondering why it is seeming to believe i am making a recursive call on the units that are set to be built?
It tells you there is a recusion because there is a recusion.

In grts_resources.locals.lua:272 you call GiveOrderToUnit, which does at some point create a unit while that call is executed (probably the build command?). This triggers the callin UnitCreated() and in grts_holdpsition.lua:30 you give the 2nd command. This all happens during the first GiveOrderToUnit. That is the recursion.

Re: recursion is not permitted on a give order to unit call?

Posted: 18 Dec 2010, 22:06
by knorke
any GiveOrderToUnit fails in UnitFinished etc.
not just build commands, even move or attack commands.
well, even "unit created by build commands" would not make sense if you think that the unit takes a while to be build and stuff.