Set multiple conditions at once

  • #1, by smac96Tuesday, 03. June 2014, 16:11 10 years ago
    Hi,

    I haven't found anything in the forum so I would like to ask you guys if there's a way to set multiple conditions at once.

    Example:

    I have 5 conditions:

    condition_1 is TRUE
    condition_2 is TRUE
    condition_3 is TRUE
    condition_4 is TRUE
    condition_5 is TRUE

    I would like to change all the conditions at once from TRUE to FALSE.

    Is there any code I could use (without setting all the 5 conditions manually with the usual action part "Change condition")?

    Thank you smile

    Newbie

    97 Posts


  • #2, by NoComTuesday, 03. June 2014, 16:28 10 years ago
    Yeah, you can write a little defined Lua Script.

    function SetBoolTrue()
    
    for i=1, 6, 1 do
    getObject('Scenes[First scene].SceneConditions[Bool_'..i..']'):setValue(VConditionValue, true)
    end
    
    end
    


    Then you call the function, when you need it.

    Or where do you store these Values? In the same place or in different ones?

    My solution is very simple and has some limits:
    The path of the values has to be the same.
    The names of the values has to be similar (like: NameBool_1, NameBool_2) it won't work, if you have different names like: BoolName_1, NameBool_2

    Newbie

    24 Posts

  • #3, by smac96Tuesday, 03. June 2014, 16:37 10 years ago
    Wonderful! smile Thank you NoCom!

    Now... I know how to call the function, but I'm not very good with LUA scripting itself... so... in a concrete code how I write it?

    Let's suppose I have 5 conditions that are all TRUE:

    condition_1
    condition_2
    condition_3
    condition_4
    condition_5

    The Scene is called "Test scene".

    And I would like to change all the conditions at once from TRUE to FALSE.

    How to write it correctly in the LUA script you showed me?

    Thank you for your patience smile

    Newbie

    97 Posts

  • #4, by NoComTuesday, 03. June 2014, 16:43 10 years ago
    Yeah no problem ^^
    function BoolChange()
    for i=1, 5, 1 do
    getObject('Scenes[Test scene].SceneConditions[condition_'..i..']'):setValue(VConditionValue, true)
    end
    end
    

    and don't forget do set the Script Properties from execution-script (left dot) to defined-script (rigth dot)
    (i use the german version, so i don't know the english name for it)

    Newbie

    24 Posts

  • #5, by smac96Tuesday, 03. June 2014, 16:46 10 years ago
    Thank you smile

    Newbie

    97 Posts

  • #6, by NoComTuesday, 03. June 2014, 16:53 10 years ago
    You're welcome ^^

    Newbie

    24 Posts

  • #7, by afrlmeTuesday, 03. June 2014, 18:00 10 years ago
    You can actually write scripts directly inside of the editor actions too with the "execute a script" action part.

    I use it quite often for writing short bits of Lua script instead of creating functions & scripts inside of the script section - saves time is all, unless you are writing a function that will be used multiple times or is global & can be used for different things.

    @NoCom: You don't have to set all 3 values for the for loop. By default it will automatically start from 1 & finish on the final (second value) you set. The third value sets the value to increase by...

    for example...
    for i = 1, 10, 0.25 do
     print(i)
    end
    
    result would be:
    1
    1.25
    1.5
    1.75
    2
    2.25
    ...
    10
    

    Also... if the condition names are unique & other conditions do not contain the same name then you can use the global conditions table instead of linking directly to them
    getObject("Conditions[condition_name]")
    

    having said this... it is better to directly link to them, when possible, because it is the safer method.

    Finally for the example above, you could have also added the names of the conditions into a table like so...
    local t = {"condition_name_1", "condition_name_2", "condition_name_3", ...}
    
    for i = 1, #(t) do -- for i is 1 to total of entries in table "t"
     getObject("Conditions[" .. t[i] .. "]"):setValue(VConditionValue, true)
    end
    

    Anyway, nice one on providing help for a lua related question! wink

    Imperator

    7278 Posts

  • #8, by NoComTuesday, 03. June 2014, 18:42 10 years ago
    Yeah thats rigth, you don't need all 3 values, but it's allways better to be exact as possible. grin

    and this one:
    local t = {"condition_name_1", "condition_name_2", "condition_name_3", ...}
    
    for i = 1, #(t) do -- for i is 1 to total of entries in table "t"
     getObject("Conditions[" .. t[i] .. "]"):setValue(VConditionValue, true)
    end
    


    thats cool, didn't know about this use of tables, i'll use that, thanks grin

    however, is it better to use the global condition tabe? because it seems quite problematic to me, when you want to create bigger games <.< (ok i could write an id-generator, to prevent double names) but i thougt using this method is better?

    getObject('Scenes[Test scene].SceneConditions[condition_'..i..']'):setValue(VConditionValue, true)
    

    (or is this this direct-link method? )

    You can actually write scripts directly inside of the editor actions too with the "execute a script" action part.

    upsie i forgot about that xD

    Newbie

    24 Posts

  • #9, by smac96Tuesday, 03. June 2014, 18:54 10 years ago
    As usual, thank you AFRLme grin

    The "execute a script" action part is simply perfect! :-)

    Now the hardest part... if the conditions are not a "sequence" (1, 2, 3, ...) but have some generic names?

    For example:

    CONDITION_BATMAN
    CONDITION_SUPERMAN
    CONDITION_HULK
    CONDITION_SPIDERMAN
    CONDITION_THOR?

    wink

    How can I say to Visionaire "change all these conditions from TRUE to FALSE"?

    Newbie

    97 Posts

  • #10, by afrlmeTuesday, 03. June 2014, 19:05 10 years ago
    with the table method I provided above. wink

    @NoCom: the way you wrote out the condition links is the direct method. Using global link (short) methods can be problematic if you have multiple instances of conditions with the same name. It's all down to how you name them. I vary between methods depending on the circumstance... but I rarely write anything with the same name twice.

    Imperator

    7278 Posts

  • #11, by smac96Tuesday, 03. June 2014, 19:09 10 years ago
    So you mean:

    getObject('Scenes[Test scene].SceneConditions[CONDITION_BATMAN]'):setValue(VConditionValue, true)
    getObject('Scenes[Test scene].SceneConditions[CONDITION_SUPERMAN]'):setValue(VConditionValue, true)
    getObject('Scenes[Test scene].SceneConditions[CONDITION_HULK]'):setValue(VConditionValue, true)
    getObject('Scenes[Test scene].SceneConditions[CONDITION_SPIDERMAN]'):setValue(VConditionValue, true)
    getObject('Scenes[Test scene].SceneConditions[CONDITION_THOR‘]'):setValue(VConditionValue, true)
    

    Newbie

    97 Posts