[Solved] Get a condition in lua

  • #1, by andy-rinaldiThursday, 25. September 2014, 11:44 6 years ago
    Hi, sorry for my dummy question: How can I get a condition using lua?

    I have tried:
    local txtP = getObject('Conditions[txtP?]')
    local txtP = getObject("Conditions[txtP?]")
    local txtP = getObject("Interfaces[vk_cmds].InterfaceConditions[txtP?]")
    local txtP = getObject("Interfaces[vk_cmds].Conditions[txtP?]")
    local txtP = getObject("Conditions[txtP?]"):getValue(VConditionValue)
    1
    2
    3
    4
    5
    6


    but them no work. shock

    Thanks.

    Forum Fan

    160 Posts


  • #2, by afrlmeThursday, 25. September 2014, 12:04 6 years ago
    To get the boolean value you have to use getBool function.
    local txtP = getObject("Conditions[txtP?]") -- short linking
    -- or getObject("Interfaces[vk_cmds].InterfaceConditions[txtP?]") -- direct linking
    1
    2
    3

    then you could query the condition like so...
    if txtP:getBool(VConditionValue) then
    -- do something
    end
    1
    2
    3
    4

    or...
    if txtP:getBool(VConditionValue) == true then
    -- do something (true)
    else
    -- do something (false)
    end
    1
    2
    3
    4
    5
    6

    ...you can even do the getObject in the query without creating a variable first.
    if getObject("Conditions[txtP?]"):getBool(VConditionValue) then
    -- do something
    end
    1
    2
    3
    4

    Imperator

    6842 Posts

  • #3, by andy-rinaldiThursday, 25. September 2014, 17:10 6 years ago
    Thanks Lee, you're the best. razz
    Now it's working.

    Forum Fan

    160 Posts

  • #4, by andy-rinaldiThursday, 25. September 2014, 17:54 6 years ago
    I have a new question. How can I switch this scene with no fade effect?

    Forum Fan

    160 Posts

  • #5, by afrlmeThursday, 25. September 2014, 18:11 6 years ago
    You need to disable fade transition I guess or change the fade transition time value.

    try...
    local fadefx = 0

    if game:getInt(VGameFadeEffect) ~= 0 then
    fadefx = game:getInt(VGameFadeEffect)
    game:setValue(VGameFadeEffect, 0)
    end
    -- + --
    game:setValue(VGameCurrentScene, getObject("Scenes[scene_name]")
    if fadefx ~= 0 then game:setValue(VGameFadeEffect, fadefx) end
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10

    ...basically we check fade effect option & if it does not equal off then we store current value & turn it off. Then we change the scene & if stored fade effect does not equal 0 then we change it back.

    We could write a workflow function for this to make it quicker. But this should work for now.

    Imperator

    6842 Posts

  • #6, by afrlmeThursday, 25. September 2014, 19:13 6 years ago
    Here's a workflow function...
    function changeScene(s, t, d, fe, fd)
    fe = game:getInt(VGameFadeEffect); fd = game:getInt(VGameFadeDelay)
    -- + --
    if t < 0 then t = 0 elseif t > 7 then t = 7 end
    game:setValue(VGameFadeEffect, t); game:setValue(VGameFadeDelay, d)
    -- + --
    game:setValue( VGameCurrentScene, getObject("Scenes[" .. s .. "]") )
    -- + --
    game:setValue(VGameFadeEffect, fe); game:setValue(VGameFadeDelay, fd)
    end
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11

    ...to use...
    changeScene("scene_name", effect int, delay int)
    1
    2

    ...scene_name is case sensitive. effect int is a number between 0 & 7. 0 being no transition & the others being the different transition types. delay int being the amount of time the transition takes in milliseconds.

    Here are the transition int values: (taken from data structure in wiki)
    Effect for fade in/out of a scene.

    '0' (eFadeNo): no effect. display new scene immediately.
    '1' (eFadeIn): fade in. Only fade in new scene. No fade out of current scene.
    '2' (eFadeOut): fade out. Only fade out current scene. No fade in of new scene.
    '3' (eFadeInAndOut): fade in/out. Fade out current scene and fade in new scene.
    '4' (eFadeToNew): fade to new. Use alpha-blending to directly fade from current to new scene.
    '5' (eShiftLeft): shift left. Shift current scene to the left and show new scene.
    '6' (eShiftRight): shift right. Shift current scene to the right and show new scene.
    '7' (eTunnelEffect): tunnel effect. Use a tunnel effect for fade in/out.
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11

    Imperator

    6842 Posts

  • #7, by andy-rinaldiThursday, 25. September 2014, 22:23 6 years ago
    Thank you Lee. Very interesting. I begin to understand lua scripting.

    Also I can set to 0 the fade effect without check before the current value of the VGameFadeEffect object.
    local fadefx = 0
    fadefx = game:setValue(VGameFadeEffect, 0)

    if txtP == true then
    game:setValue( VGameCurrentScene, getObject("Scenes[0015commands_clearENG]"))
    game:setValue(VGameFadeEffect, fadefx)
    end
    1
    2
    3
    4
    5
    6
    7
    8

    wink

    Forum Fan

    160 Posts

  • #8, by afrlmeThursday, 25. September 2014, 22:30 6 years ago
    hmm the problem with what you have just written is that you are not restoring the original fade effect value afterwards.

    I recommend using the workflow function I added to the wiki earlier on @ here.

    Also I recommend checking out my other workflow functions as there are functions for checking conditions, setting conditions, setting values (string or int) & various other things.

    http://wiki.visionaire-tracker.net/wiki/Compiled_Index_of_Lu...

    P.S: lua script in VS is not exactly the same as lua script in general because VS uses some functions & tables that are exclusive to VS, but the general principal of lua script still applies.

    Imperator

    6842 Posts

Write post