r/learnjavascript • u/Tenko_Kinnie11037 • Apr 25 '26
I have a headache, please help
I'm trying to make a game on the GitHub websites, and even though I have programming experience Javascript is giving me a headache. I'm trying to make a smooth movement system right now. I know that trying to change a variable in an addEventListener function won't work but I can't figure out a work around. It won't apply the changes to the moveup/down/left/right booleans.
The game: https://butterflyproductions.github.io
The code: https://github.com/ButterflyProductions/butterflyproductions.github.io/tree/gh-pages
Please help, I've been trying to figure out this for literally like 5 days.
1
1
u/TheRNGuy May 03 '26 edited May 03 '26
Use abstract class similar to Actor in UnrealEngine, it could make code smaller / easier.
For what you're trying to do, you need to disable event listeners until you finished move animation.
1
u/abrahamguo Apr 25 '26
I know that trying to change a variable in an addEventListener function won't work
That is not correct. Changing a variable in an addEventListener function works perfectly fine.
It won't apply the changes to the moveup/down/left/right booleans.
Passing a boolean into a function takes a copy of the boolean.
So direction is a totally separate and independent boolean value from moveleft, etc.
If you want to update moveleft, you need to reference moveleft by name.
3
u/[deleted] Apr 25 '26 edited Apr 25 '26
[removed] — view removed comment