Lua to control visibility/activation of objects

  • #1, by pietro-eccherFriday, 08. November 2019, 12:28 4 years ago
    Hi, as the title says: I'd like to check more than one condition/value to show an object (and enable interaction with it) and I thought to use a simple scripted if because the editor allows only to check on 1 condition/value.

    How is the "enable object" property named if it has to be accessed from a lua script? I suppose it's a bool value. Am I right?

    Thank you


    Newbie

    29 Posts


  • #2, by SimonSFriday, 08. November 2019, 13:28 4 years ago
    Hi, the object is always toggled by a condition and cannot be enabled manually. So you need to add a condition that you change to accomplish this.

    Thread Captain

    1580 Posts

  • #3, by afrlmeFriday, 08. November 2019, 18:56 4 years ago
    use a value. you can set the value based on multiple conditions.

    let's say you want it to be active when value "example" is set to 1.

    so what you could do is something like this...

    execute a script...
    if Conditions["a"].Value and Conditions["b"].Value then
    
      Values["example"].Int = 1
    
    else
    
      Values["example"].Int = -1
    
    end


    So yeah it's possible to do with multiple conditions/values as long as you use a single condition or value to toggle the object state. You can mix it up with as many and/or queries as you like, but you would need to check each time you update one of the values/conditions wink

    Imperator

    7278 Posts

  • #4, by pietro-eccherFriday, 08. November 2019, 21:39 4 years ago
    Thank you, another question:
    is it possible to nest if conditions in the action chain?

    I have this pseudo situation but it's not working as expected: the first IF layer works, then it seems to check correctly for condition_2 (it does "other stuff")
    When I get back to the action chain with a new click and condition_2 is false it doesn't execute the second layer ELSE (do something).

    IF condition 1 is true
    do stuff
    ELSE
    IF condition 2 is true
    do other stuff
    CHANGE CONDITION 2 to FALSE
    ELSE
    do something
    END IF
    END IF

    Should I handle it with lua returning different values and check those?
    Thank you in advance

    Newbie

    29 Posts

  • #5, by afrlmeSaturday, 09. November 2019, 00:59 4 years ago
    With action parts it's less flexible than using if lua result action part, but sure you can check multiple conditions/values with action parts. There's no method for AND/OR with action parts, but there is ELSEIF, which allows you to do multiple if queries & only need a single end if. wink

    if condition "a" is true
     do something
    elseif condition "b" is true
     do something
    else
     do something
    end if

    Imperator

    7278 Posts

  • #6, by pietro-eccherSaturday, 09. November 2019, 02:01 4 years ago
    Thanks, I think I will stick to lua it's even faster to write smile
    Is there a way to undock the scripting panel when I "execute a script" in the action chain? On my monitor it is really "thin" while lines can be very long smile

    Newbie

    29 Posts

  • #7, by afrlmeSaturday, 09. November 2019, 02:57 4 years ago
    Unfortunately no. I highly recommend writing scripts in atom or sublime text editor (if you are planning on writing long/complex scripts) & pasting them into VS when you are done.

    If it's something small then just write it directly in the editor, or don't - it's up to you.

    In regards to the text editors I just mentioned: atom is 100% free (made by github devs), & it's almost as good as Sublime Text. I use both of them, but Sublime Text is my preferred text editor for scripting, & can also be used for free as the unlicensed version has no time limit on it, but will popup a message every x random saves asking you to consider purchasing a license.

    Imperator

    7278 Posts