Set frame range error [SOLVED]

  • #1, by red363Thursday, 18. May 2023, 17:38 12 months ago
    Hello.
    I am using script to select animation frame:
    https://wiki.visionaire-tracker.net/wiki/SetAnimFrames_(CMS)

    Everything works, but for some reason it causes a repeating error:

    18:19:03.606:stack traceback:
     [C]: in metamethod 'newindex'
     [string "(30,57)"]:9: in function 'setAnimFrames'
     [string "(8,33905)"]:17: in main chunk
    18:19:03.606:Unknown data-field "FirstFrame" for object (-1,-1) Unnamed.
    18:19:03.607:1
    18:19:03.607:stack traceback:
     [C]: in metamethod 'newindex'
     [string "(30,57)"]:8: in function 'setAnimFrames'
     [string "(8,33905)"]:18: in main chunk
    18:19:03.607:Unknown data-field "LastFrame" for object (-1,-1) Unnamed.

    and so on...

    My script is placed in the first frame of object animation (call action function):

    local val = Values["choice"].Int
    if val == 1 then
    setAnimFrames("char1", 2)
    setAnimFrames("char2", 1)
    setAnimFrames("char3", 1)
    setAnimFrames("char4", 1)
    setAnimFrames("char5", 1)
    setAnimFrames("char6", 1)
    elseif val == 2 then
    setAnimFrames("char1", 1)
    setAnimFrames("char2", 2)
    setAnimFrames("char3", 1)
    setAnimFrames("char4", 1)
    setAnimFrames("char5", 1)
    setAnimFrames("char6", 1)
    elseif val == 3 then
    setAnimFrames("char1", 1)
    setAnimFrames("char2", 1)
    setAnimFrames("char3", 2)
    setAnimFrames("char4", 1)
    setAnimFrames("char5", 1)
    setAnimFrames("char6", 1)
    elseif val == 4 then
    setAnimFrames("char1", 1)
    setAnimFrames("char2", 1)
    setAnimFrames("char3", 1)
    setAnimFrames("char4", 2)
    setAnimFrames("char5", 1)
    setAnimFrames("char6", 1)
    elseif val == 5 then
    setAnimFrames("char1", 1)
    setAnimFrames("char2", 1)
    setAnimFrames("char3", 1)
    setAnimFrames("char4", 1)
    setAnimFrames("char5", 2)
    setAnimFrames("char6", 1)
    elseif val == 6 then
    setAnimFrames("char1", 1)
    setAnimFrames("char2", 1)
    setAnimFrames("char3", 1)
    setAnimFrames("char4", 1)
    setAnimFrames("char5", 1)
    setAnimFrames("char6", 2)
    else
    setAnimFrames("char1", 1)
    setAnimFrames("char2", 1)
    setAnimFrames("char3", 1)
    setAnimFrames("char4", 1)
    setAnimFrames("char5", 1)
    setAnimFrames("char6", 1)
    end


    Can you suggest what could be the problem??
    Thanks

    Forum Fan

    101 Posts


  • #2, by afrlmeThursday, 18. May 2023, 18:05 12 months ago
    It's either trying to access something that doesn't exist, or it's trying to access an active animation that's not actually active or isn't loaded yet.

    Also instead of that massive list of else if, why didn't you consider using a table or using iteration?
    for i = 1, 6 do
    
     if Values["choice"].Int == i then
    
      setAnimFrames("char"..i, 2)
    
     else
    
      setAnimFrames("char"..i, 1)
    
     end
    
    end


    Imperator

    7278 Posts

  • #3, by red363Thursday, 18. May 2023, 21:10 12 months ago
    Thank you. In my case, this is an animation that is not yet loaded / active.

    Tables... I don't know how to work with that. Will be studying

    Forum Fan

    101 Posts

  • #4, by afrlmeThursday, 18. May 2023, 23:37 12 months ago
    The code I shared wasn't a table. It was a short iteration method example using the for loop, which does the same as your if else queries, except it's much less code. wink

    Imperator

    7278 Posts

  • #5, by red363Friday, 19. May 2023, 00:19 12 months ago
    The code I shared wasn't a table. It was a short iteration method example using the for loop, which does the same as your if else queries, except it's much less code. wink
    Yes, I got it, thanks. Very handy for these occasions

    Forum Fan

    101 Posts

  • #6, by red363Friday, 19. May 2023, 04:01 12 months ago
    Can this error create any problems? reduce performance? 
    So everything works...

    This solutionis convenient to use for "highlighting" items in the inventory (so as not to highlight empty cells)...

    Forum Fan

    101 Posts

  • #7, by red363Friday, 19. May 2023, 05:25 12 months ago
    Is it possible to track in the inventory whether the cell is filled with an item or not?

    For example:
    click to placeholder for items:
    if placeholder is full - do something (animation)
    else - nothing

    Forum Fan

    101 Posts

  • #8, by afrlmeFriday, 19. May 2023, 21:10 12 months ago
    1. The log messages are just warnings, so they shouldn't really impact performance, however it would be ideal to try & remedy the issues so that you don't have any warnings/errors being generated - add a small pause or something before trying to force the animation frames in whatever method you are using to prevent it trying to update them before they've all started playing. Or you could add the code directly into the frames themselves as that way they will definitely be playing when the code is executed.

    2. You could use the mouse event handler to check if an object exists below the cursor & that it's an item. Another thing you could do is use code to check how many items exist in the character inventory & set a value to that so you can check how many slots are filled up.

    Values["example"].Int = #game.CurrentCharacter.Items

    Imperator

    7278 Posts

  • #9, by red363Friday, 19. May 2023, 21:49 12 months ago
    1. The log messages are just warnings, so they shouldn't really impact performance, however it would be ideal to try & remedy the issues so that you don't have any warnings/errors being generated - add a small pause or something before trying to force the animation frames in whatever method you are using to prevent it trying to update them before they've all started playing. Or you could add the code directly into the frames themselves as that way they will definitely be playing when the code is executed.

    2. You could use the mouse event handler to check if an object exists below the cursor & that it's an item. Another thing you could do is use code to check how many items exist in the character inventory & set a value to that so you can check how many slots are filled up.

    Values["example"].Int = #game.CurrentCharacter.Items
    Cool, thanks a lot! This is a great option

    Forum Fan

    101 Posts

Write post