For some reason, I decided to try a Youtube tutorial on making games with the Godot engine. The tutorial is well done and covers many different aspects – HeartBeast’s Action RPG tutorial – and now I’m part way into two more tutorial video series on game development.
Everything is a bit more complex than it first appears. For the player character to swing it’s sword, there needs to be input and actions associated with the input, a state machine for switching between states, a hitbox for the sword and a hurtbox for the target (so you can register if the swing hit by comparing areas or seeing if an area was entered), etc, etc.
It’s not surprising because I am building, under careful guidance, a small world with all of its rules. Objects don’t fall unless I specify gravity and what it is (or give it to a physics process, which is the same thing but written by someone else). Characters don’t make decisions until I build their brains (logic).
I ran into a problem where my player would swing its sword and hit an enemy and the damage would be registered two times. After beating my head on the problem for awhile, I went to Discord and asked. Two people helpfully suggested breakpoints and being sure that the sword was only set to 1 damage. (breakpoints are a piece of code that tells the game engine to stop processing and show the debugger at that line). The damage was not set to anything so it should have been subtracting one for the strike, but the breakpoint showed that my code where it was subtracted ran twice in a row.
A few minutes later, I found that I had accidentally duplicated the entire node: the player, scenery, and enemies. Because the logic was simple, all of them acted identically on top of each other. My stacked players walked to the stacked enemies, swung their swords, and both of the stacked enemies registered hits from both of the players, and both disappeared at the same time.
Maybe if I built a test module that showed each enemy onscreen with stats…
Edit: I had checked my enemy scripts and player scripts over and over but didn’t step back and look at the main scene (where the duplication was) because everything there was “working right”. Everything was actually working right, just twice.