Ask coding questions

← Back to all posts
an issue using onended
AstrumDeorum (142)

using onended for my sounds, sometimes it runs the damage after the sound, but for a lot of it, it doesn't wait for the damage to finish.
All I'm doing is this line:;
attacksoundSFX.onended = opAttack(2);

Any Help is appreciated

Coder100 (18118)

you actually just called the function instead of assigning it to be called instead. Please assign a function for a function to take effect!;
attacksoundSFX.onended = () => opAttack(2);
AstrumDeorum (142)

@Coder100 That works! However:
My next issue is, there are 2 moves that need to use this code, and are shared by team and opponent, so trying this code will end up in both sides running the attack at the same time, which is a problem.
Do you know the solution to that?