Login / Registrieren
DE EN FR ES IT CZ
Zurück Nach oben

check if an animation is running in lua

  • #1, by PanS 7 years ago Zitieren
    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
    
  • #2, by sebastian 7 years ago Zitieren
    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.
  • #3, by PanS 7 years ago Zitieren
    You mean like that:
    if ActiveAnimations(anim_res_fullscreen) then
    
  • #4, by sebastian 7 years ago Zitieren
    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

  • #5, by afrlme 7 years ago Zitieren
    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 

  • #6, by PanS 7 years ago Zitieren
    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
  • #7, by sebastian 7 years ago Zitieren
    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
  • #8, by PanS 7 years ago Zitieren
    Ah, thx a lot. Thats very helpful.
  • #9, by afrlme 7 years ago Zitieren
    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.
  • #10, by sebastian 7 years ago Zitieren
    edit: I believe you can now just query .Value instead of .ConditionValue.
    yep wink