#how to preload animations and call them in another script
1 messages · Page 1 of 1 (latest)
Why
i have lots of tool and have to switch between them fast
soi wanna preload the anims
But why call them in another scripts
the tool scripts
im trying to preload them all in a single script so when i equip the tools it does have delays loading anims
Content provider and using module scripts
how
im doing that theres delays
so i call the module function from a script, then require the module and play the anims on the tool?
You can use the module script to handle the animations
** You are now Level 6! **
and call it in another script using methods
i load all the animations by calling the module function, then add every loaded animation into a table and get an animation on the tool script as a variable?
i do this in my game, here is an example (you'll have to add the code yourself)
`-- use CharacterAnimations[AnimationName] to index the track in any other script
local CharacterAnimations = {}
local animDictionary = {
AnimationName = 123456789
}
function CharacterAnimations:LoadAllOntoCharacter(char)
-- load them onto the Animator with a CharacterAdded event
end
return CharacterAnimations`
yeah but how do i get the animations when i need them
without having to load again
this module is just a table that happens to have a method in it (LoadAllOntoCharacter), so you just call the Track's name after adding it to the table in the method
in my example, after you load the track onto the character's animator, you would do CharacterAnimations[AnimationName] = AnimationTrackObject
great, let me know if you have any more questions!
if you dont mind, can tou teach me module methods
bc i only use modules for functions and tables
i'm not suuper familiar with the lua internals, but from what I understand module's methods are members of a table module that are just a function instead of a regular value, since tables can have any type. so after loading stuff the above module would probably look like this:
CharacterAnimations: { LoadAllOntoCharacter = function() AnimationName = 123456789 }
sorry pressed enter too soon
will edit
you can also print a module with a method and it'll tell you the real interior!
** You are now Level 1! **
so whats the difference between using . and :
i'm pretty sure the main difference is that : calls a function with the module as the first argument. so CharcterAnimations:LoadAllOntoCharacter() is actually CharacterAnimations.LoadAllOntoCharacter(CharacterAnimations).
ts is so confusing lol
here the first parameter is char no?
yes, CharacterAnimations is passed automatically. i believe if you tried doing CharacterAnimations**.**LoadAllOntoCharacter, you wouldn't be able to access CharacterAnimations in the interior of the function