Condition Woes

All discussions & material related to Command's Lua interface

Moderators: RoryAndersonCDT, michaelm75au, angster, MOD_Command

Post Reply
jkgarner
Posts: 175
Joined: Thu Apr 30, 2020 12:42 pm

Condition Woes

Post by jkgarner »

OK,

I'm trying to set a condition on my recurring time event (interval of 30 seconds... but the interval is unimportant)

The following code example was in the documentation as an example condition:

Code: Select all

ScriptTest='--comment\r\nif unit ~= nil then\r\n return true\r\n else\r\n return false\r\n end'
Well, for starters, for it to work, I must set ScriiptText, not ScriptTest in the version that I am running. I can't speak to whether it has since been changed to ScriptTest. Secondly, where is unit defined in this code? IN forum posts, I have seen uniot being set by calls to ScenEdit_UnitX. Is there a unit object available to querying on a condition? When I wrote code referencing a unit, without defining it with a ScenEdit_GetUnit call first, it failed spectacularly, actually, it simply failed all tests and died with a whimper.

I wrote what I thought was a reasonable condition, returning true and false, like the example, but all I get if condition fails, even when I manually verify that the condition should be true... it fails.

Here is my code:

Code: Select all

	local cScript = ""	
 	cScript = cScript.."local unit = ScenEdit_GetUnit({side= '"..side_name.."', name = '"..unit_name.."'})'".."\r\n"
 	cScript = cScript.."if(unit ~= nil) then return (unit.speed == 0) end\r\n"
 	cScript = cScript.."return false"
 	
 	--return (unit.speed == 0)
 	ScenEdit_SetCondition({mode='add', Description=eName, type='LuaScript', ScriptText=cScript})	
 	ScenEdit_SetEventCondition( eName, {Mode='add', name=eName})
side_name and unit_name are defined in the event generating function as strings holding the side and unit names.

From what I can find in the help, I am supposed to return true for success (proceed with he action) or false, for fail the condition, to block the action. This is what I have done, but it registers fail at every call.

What am I missing?[&:]

On a side note: the documentation of intervals for recurring event triggers should be rewritten to tell the reader that the parameter is an integer, with 0 being '1 sec', 1 being 5 seconds, 2 being 15 seconds, and so forth. I had to crash my scenario 3 times to figure that out.


jkgarner
Posts: 175
Joined: Thu Apr 30, 2020 12:42 pm

RE: Condition Woes

Post by jkgarner »

FOUND IT!

The script generation code tosses in an extra ' at the end of the first line, causing it to error our when called.

The documentation still needs attention. But am happier.[8D]
Post Reply

Return to “Lua Legion”