i'm asking your help because i have issues with a function. I'm trying to generate a random animation, and the solution i found is using a switch state with a Math.random() to match every case and returning a string that match the animation in my other Table.
Here's the code, so maybe it'll be more understanable
function PickAnimation () {
let value = Math.floor(Math.random() * 4);
const animationList = ['idle', 'attack', 'walk']
switch(value) {
case 1:
return result = animationList[0];
case 2:
return result = animationList[1];
case 3:
return result = animationList[2];
default:
return result = animationList[0];
}
}
setInterval(PickAnimation(), 1000)
The issue is that it is actually working for the first animation which is random as expected, but then when i set a set interval, it says that for example 'idle is undefined'
I've search for solution everywhere but did not find any working solutions.
I'll be glad to have some answers about this, thanks !