Variables return 0 for no reason

Before proceeding, please use the forum search feature at the top of the page to check if your question has already been answered.

How do I…

Make the variable return its original value instead of a zero?

What is the expected result

I’m using the variables to make specific damage for certain characters in a fighting game so that the players can choose a character that matches their playstyle.

What is the actual result

I try to attack and it does nothing, i changed “subtract” to “set to” and it sets their health to 0.

Extra info

I tried to do the variables all with the same name, but have them be the character’s variables and call them using groups, didnt work so i tried making them global variables and setting them at the beginning of the scene, also didnt work. I also made sure to check the code incase the variables get changed by a different line of code, alas nothing. cant put screenshots due to being a new user… id rather just do them in the thread.

Really need help gang :pray:

Hello and welcome. Snip some pertinent events so we can see what’s going on.

You use unconventional terminology.It might take some time to unpack this.

“I tried to do the variables all with the same name”
What does this mean? What is the “do” verb doing? And what do you mean by “same name”?

“but have them be the character’s variables”
Object variables rightr?

“and call them using groups”
What does “call them” refer to and how are groups involved in this?

“didnt work so i tried making them global variables and setting them at the beginning of the scene, also didnt work.”
What exactly didn’t work?

You want a variable to return non-zero but then go on to state " i changed “subtract” to “set to” and it sets their health to 0.". So it sounds like you are getting exactly what you are asking for.

so, i placed the characters into to two groups “p1” and “p2” with copies of the characters etc. all of the characters share the same names for variables, so i can call them from the group, which makes it easier to have a ton of characters and just change the variables depending on the character’s stats. by “character’s variables” i do mean the object’s variables. the “not working” statement refers to when i try to return those variables, the value comes out to 0, when i said that it “set to 0” i meant that i did that to test whether the collisions were working or not, but since it set it to 0, i concluded that the problem was that the value is zero.

I tried to run the game in debugger mode, to check if the variables change value at all, but they have the value that they’re supposed to have, yet they still return 0.

sorry for the bad terminology, not used to talking about coding to anyone, and thanks for trying to help :slight_smile:









sorry for the scuffed code

Please describe what you are trying to achieve. Not how you are trying to achieve it. These are two very different things.

i want to assign different damage numbers to different characters and attacks, but when i try return them, they’re all 0

Good, now it’s clear. However, you posted the entire source code. That will take me half an hour to read through, can you just show the relevant events please?

i sent all of it just in case but sure ill send all the events that are related


this is for player 1 to get damaged, the points are the attacks of player 2.

“p2light” is the variable with the specific damage, but when the condition is met, it just results in a 0 being subtracted instead

I don’t see in your logic that damage values are ever assigned.

Values are set during check for “player1choice”, but I don’t see where that variable is defined…

When you create a new system, for example weapon damage, it needs to be developed and tested in the most narrow, self-contained way. That is, make sure basic damage calcs work before you start adding lots of different types of attacks and animations and behaviors. Make things work one at a time instead of trying to do many things simultaneously.

oh mb, the variables is inside the characters and i asked for the wrong variable.


since its in the group “p2” i used “p2.Light”, but it still doesnt work

but where is Player1Choice defined?

oh, different scene for character select

I would seriously focus on cleaning up the code before adding anything else.

You have a character select function. Later in the game, every frame, you check which character was selected and set the damage numbers accordingly.

So you select a character once, then 60 times a second check which character was selected. You only need to check once. Set the damage values at the character select stage, not every frame.

You create objects when chekcing playerChoice. Is this created every frame?

Similarly, you have a number of events which respond to a mouse click. But each node checks for the mouse click. Make one single event which checks the click, then add the rest as sub-events.

Drop PlayerChoice completely and just set the relevant damage numbers etc at the end of character select, then don’t touch those values ( light/air/crouch ).

You check whether HP <= 0, and then in the next event handle damage calcs. Process damage calcs before you check whether a player died because of damage. Damage comes first, death comes second. The same happens with checking whether points are inside P1/P2. Lots of unnecessarily duplicated code. This leads to problems with stability.

You check whether S key is pressed AND not released at the same time. A key can’t be pressed and released at the same time. Unnecessary code. You also check S several times. Only check once. Same with slash key.

thanks for the pointers!! ill do all those first thing then ill report back to you on whether or not things work properly etc.

thanks a ton for helping out! :slight_smile:

1 Like