Lua Animation Function Issue

  • #1, by ygmantellMonday, 29. January 2018, 19:13 2 years ago
    So, I'm trying to play an outfit animation via Lua, so I can have a single function for an animation independant from what outfit a character is wearing, however, it's just not working...

    First I tried this:
    function charAnim(c, a)
          if c == nil then c = game.CurrentCharacter:getName() end
          startAnimation( Characters[c].CurrentOutfit.OutfitCharacterAnimations[a] )
    end 
    1
    2
    3
    4

    Then calling it via charAnim("Player", "useRight")

    But then nothing happens.  In the log, I get this:
    12:04:15.737:Visobj useLeft could not be found in linklist
    12:04:15.737:Wrong argument type for Argument #1 (expected visobject)
    12:04:15.738:[string "(30,9)"]:5: Invalid syntax for command startAnimation
    12:04:15.738:stack traceback:
     [C]: in function 'debugerror'
     [string "function debugfunc(err) debugerror(err) end"]:1: in function
     [C]: in function 'startAnimation'
     [string "(30,9)"]:5: in function 'charAnim'
     [string "(8,89)"]:1: in main chunk
    12:04:15.738:Failed to run string in Lua:
    12:04:15.738:String content: charAnim("Player", "useLeft")
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11


    "useLeft" is a Character animation name for my player, so I'm not sure why I got that error.
    I tried "useRight" (also an animation name) and nothing happened.  Nothing in the log either.

    Any ideas?

    Thanks so much!

    Great Poster

    274 Posts


  • #2, by trepnMonday, 29. January 2018, 21:09 2 years ago
    Looks like the function is receiving "useLeft" as value for a and can't find anything for it. Try printing all the variables in the function to see where it goes wrong.

    Newbie

    60 Posts

  • #3, by sebastianMonday, 29. January 2018, 23:38 2 years ago
    could you try saving the animation in a variable and then use 

    startAnimatiin(varname)

    Thread Captain

    2334 Posts

  • #4, by ygmantellTuesday, 30. January 2018, 00:54 2 years ago
    @trepn

    I tried printing out the values.  If I use "useRight" as the animation name, nothing happens and it prints "Player" and "useRight"

    However, if I use "useLeft" as the animation name, I get this in the log:

    18:47:36.038:Visobj useLeft could not be found in linklist
    18:47:36.038:Wrong argument type for Argument #1 (expected visobject)
    18:47:36.038:[string "(30,9)"]:4: Invalid syntax for command startAnimation
    18:47:36.038:stack traceback:
     [C]: in function 'debugerror'
     [string "function debugfunc(err) debugerror(err) end"]:1: in function
     [C]: in function 'startAnimation'
     [string "(30,9)"]:4: in function 'charAnim'
     [string "(8,89)"]:1: in main chunk
    18:47:36.038:Failed to run string in Lua:
    18:47:36.038:String content: charAnim("Player", "useLeft")
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11

    @sebastian

    I put the useLeft into a variable like this:
    useLeft = game.CurrentCharacter.CurrentOutfit.OutfitCharacterAnimations["useLeft"]
    1

    and when I call it in StartAnimation(useLeft) then I get this in the log:
    18:53:18.578:[string "(8,89)"]:1: attempt to call global 'StartAnimation' (a nil value)
    18:53:18.578:stack traceback:
     [C]: in function 'debugerror'
     [string "function debugfunc(err) debugerror(err) end"]:1: in function 'StartAnimation'
     [string "(8,89)"]:1: in main chunk
    18:53:18.579:Failed to run string in Lua:
    18:53:18.579:String content: StartAnimation(useLeft)
    1
    2
    3
    4
    5
    6
    7

    Great Poster

    274 Posts

  • #5, by ygmantellTuesday, 30. January 2018, 01:06 2 years ago
    Huh, okay, I figured something weird out.  Apparently the object model won't be able to reference mirrored animations...?  For me, "useLeft" is a mirrored animation of "useRight" which is why "useRight" works fine and "useLeft" doesnt.

    Is there any way around this?

    PS:  Is there a version of startAnimation with wait for animation to finish?

    Thanks so much!

    Great Poster

    274 Posts

  • #6, by afrlmeTuesday, 30. January 2018, 01:24 2 years ago
    For some reason it seems to be the fallback line that's causing it. Just delete or comment out the if c == nil line. Animations played fine for me after that & no longer printed any errors.

    Also yes mirrored animations suck. They often cause issues when it comes to scripting. I highly recommend creating unique animations for each direction.

    Imperator

    6804 Posts

  • #7, by ygmantellTuesday, 30. January 2018, 01:29 2 years ago
    Ah, got it, thank you, as always grin

    Aw, that is annoying, but thanks for clarifying!

    Great Poster

    274 Posts

Write post