check if an animation is running in lua

  • #1, by PanSTuesday, 27. November, 16:49 A week 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
    1
    2
    3
    4

    Newbie

    37 Posts


  • #2, by sebastianTuesday, 27. November, 18:43 A week 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

    2256 Posts

  • #3, by PanSTuesday, 27. November, 18:57 A week ago
    You mean like that:
    if ActiveAnimations(anim_res_fullscreen) then
    1
    2

    Newbie

    37 Posts

  • #4, by sebastianWednesday, 28. November, 01:32 A week 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

    2256 Posts

  • #5, by AFRLmeWednesday, 28. November, 05:12 A week ago
    ActiveAnimations["example"].Active
    1

    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
    1
    2
    3
    4
    5
    6

    Imperator

    6366 Posts

  • #6, by PanSWednesday, 28. November, 13:54 A week 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
    1
    2
    3
    4
    5
    Why I have to do this instead:
    local g_resolution = getObject("Values[value_resolution]")
    if g_resolution.Int >; 2 then
     ...
    end
    1
    2
    3
    4
    5

    I though values are integers. The same thing with:
    ActiveAnimations["example"].Active
    1
    2
    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

    37 Posts

  • #7, by sebastianWednesday, 28. November, 14:00 A week 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

    2256 Posts

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

    Newbie

    37 Posts

  • #9, by AFRLmeWednesday, 28. November, 22:54 A week 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
    1
    2
    3


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

    not I believe is only valid for boolean queries.

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

    Imperator

    6366 Posts

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

    Thread Captain

    2256 Posts

Write post