View Full Version : Conditional jumps on basis of values from LUA
McRib
November 7th, 2002, 06:03 AM
Hi!
I've run into a problem when using LUA to manipulate values:
Let's suggest I've got possible values from 1 to 3 in "test" generated by a variable manipulation script - this means an SimpleOSD with Icon/Device [test] shows a value from 1 to 3.
Now I want to make a conditional jump on basis of the value contained in "test". How can I do that ?
Mark F
November 7th, 2002, 06:39 AM
Is this what you mean?
if (test == 1) then
-- do 1
elseif (test == 2) then
-- do 2
elseif (test == 3) then
-- do 3
end
If you are looking for a way to do a COMMAND based on a LUA variable, look at the Switch plugin. :)
McRib
November 7th, 2002, 06:58 AM
Code example: No, I didn't mean this.
While the Switch-Plugin is exactly (thank you SO much), what I needed in this case, I'd like to under stand the background a bit better:
My intention was to do the same as Switch does in a complex way - just for only one condition - i.e. something like a Switch with only one comparision like if/then/else. Or to put it the other way - like the action "Girder/Window Exists" but branching not based on the existence of a window but on the contents of a variable.
Mark F
November 7th, 2002, 07:10 AM
If you only want to have a true/false branch, you can use the LUA variable named result to accomplish this. At the end of every LUA script command, Girder inspects the value of this variable and executes one of two commands based on if result == TRUE or FALSE. The commands to execute are chosen using the two browse buttons on the Girder tab. The top one is for TRUE and the bottom is for FALSE. Better? :)
By the way, TRUE is non-0 and FALSE is 0. ;)
McRib
November 7th, 2002, 07:16 AM
That's it! Perfect - thank you...
Powered by vBulletin® Version 4.1.8 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.