check if an animation is running in lua

  • #1, by PanSTuesday, 27. November 2018, 16:49 6 years ago
    I used the wiki, forum search and google. I can't find a way how to check if an animation is currently running in lua.

    Is that working at the end?

        if getObject("Animations[anim_res_fullscreen]").getBool(VConditionValue) == false then
          startAnimation("Animations[anim_res_fullscreen]")
        end
    

    Newbie

    73 Posts


  • #2, by sebastianTuesday, 27. November 2018, 18:43 6 years ago
    if an animation is active, it should be inside the ActiveAnimations table.
    so theoretically you could iterate through all ActiveAnimations and check if there is one with the desired name.

    Thread Captain

    2346 Posts

  • #3, by PanSTuesday, 27. November 2018, 18:57 6 years ago
    You mean like that:
    if ActiveAnimations(anim_res_fullscreen) then
    

    Newbie

    73 Posts

  • #4, by sebastianWednesday, 28. November 2018, 01:32 6 years ago
    not sure. An if statement asks for a bool as a return when you just ask "if X then..."

    because its an object it could return, im not sure if it gets handled as true/false. 

    You could try and see if a check against "nil" will do the trick :

    if ActiveAnimations["anim_res_fullscreen"] ~= nil then
        ... 
    end

    Thread Captain

    2346 Posts

  • #5, by afrlmeWednesday, 28. November 2018, 05:12 6 years ago
    ActiveAnimations["example"].Active

    Should return a true or false answer even if the animation doesn't exist in the active animations table or the animation is preloaded, but isn't playing. should only return true if it's currently playing - I think.

    But as Sebastian said, you could also iterate through the ActiveAnimations table to see if you find a match.

    function animPlaying(anim)
     for i = 1, #ActiveAnimations do
      if ActiveAnimations[i]:getName() == anim then return true end -- anim already playing
     end
     startAnimation(Animations[anim]) -- anim not playing, start it 
    end 

    Imperator

    7285 Posts

  • #6, by PanSWednesday, 28. November 2018, 13:54 6 years ago
    Thx for your answers. As I had to determine, it isnt necassary to check if an animation is allready active before you starting it. *faceplam*

    But on the other hand side some lua/visionaire scripting things I dont understand.
    Why I cant simply check an value by doing this:
    local g_resolution = getObject("Values[value_resolution]")
    if g_resolution > 2 then
     ...
    end
    
    Why I have to do this instead:
    local g_resolution = getObject("Values[value_resolution]")
    if g_resolution.Int > 2 then
     ...
    end
    

    I though values are integers. The same thing with:
    ActiveAnimations["example"].Active
    
    Where I can find a wiki or a tutorial about things like .Int or .Active?
    I didnt find something about in the visionaire wiki. Sry for that stupid question, its the really first time I try to use more lua in my project (without only copy-pasting other scripts) grin

    Newbie

    73 Posts

  • #7, by sebastianWednesday, 28. November 2018, 14:00 6 years ago
    The Visionaire Values are more than just an int. Its an internal object which holds some more stuff:


    As you know the VS Values can also contain a string or need to hold a random number min/max if the number in it should be random.

    Therefore you need to access the field you want inside the Value object.

    By the way: you are still using a very old method ("getObject()") to access these fields.  Its much simpler now:

    local g_resolution = Values[value_resolution].Int

    Thread Captain

    2346 Posts

  • #8, by PanSWednesday, 28. November 2018, 15:35 6 years ago
    Ah, thx a lot. Thats very helpful.

    Newbie

    73 Posts

  • #9, by afrlmeWednesday, 28. November 2018, 22:54 6 years ago
    Values contain 2 fields. Int & String, which is why you need to tell it what to access otherwise it's just trying to access a table.

    Conditions are the same. Conditions["example"].ConditionValue, but you don't need to query if it equals true or false because it returns a boolean value.

    if Conditions["example"].ConditionValue then
     -- true do something
    end


    if not Conditions["example"].ConditionValue then
     -- false do something
    end

    not I believe is only valid for boolean queries.

    edit: I believe you can now just query .Value instead of .ConditionValue.

    Imperator

    7285 Posts

  • #10, by sebastianFriday, 30. November 2018, 08:51 6 years ago
    edit: I believe you can now just query .Value instead of .ConditionValue.
    yep wink

    Thread Captain

    2346 Posts