• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Code doesn't work like expected

T

Tchangla

Guest
I have being coding a turn-based combat system for my Dungeon Crawler, but it is making weird things.
I have the codes distributed in diferent "execute codes" in one Step event (every "Execute code" uses a diferent variable, for moving in different "Execute codes" (sorry if I'm being redundant, I don't know exactly how to explain this better).

upload_2016-6-21_12-51-44.png

The problem I'm having, is in the last "Execute code".

///Restar/sumar vida y mostrar daño en pantalla
if(showDamage==1){

scr_battleText("b0001",damage);
showDamage=0;
}



The "scr_battleText("b0001",damage); creates a textbox with a certain text in it on screen. For some reason, the textox appear, but I can't make it dissapear pressing A (like it would work if I call it from any part of the code). I supposed that maybe the step event created X numbers of it, but since "showDamage=0" underneath of it, it should only execute that script one time. (in the picture below, the textbox is shown, but I can't interact with it).

upload_2016-6-21_12-58-11.png

Maybe I misenderstood the way GML do its things (i've programmed in Java and C#).

Any ideas? Thanks in advance.
 
L

leonfook29

Guest
Not sure about this but you didn't mention whether the text box is an object or not. It would be cool if you could tell us how you make the text disappear. Other than that, if your guess of it spawning multiple text box, maybe the variable showDamage get loop and being set to 1 over and over again?

It's easier to confirm it using debug mode, or you can check it by drawing the text of instance_number(textbox_obj)
 
T

Tchangla

Guest
Sorry, yeah, the textbox is an object that is called from the script with the custom text in it. I did this "instance_number(battText)" in the draw event, and...

upload_2016-6-21_13-14-36.png

It keeps counting and counting, I assume that is creating multiple instances of it? I don't know what it does that "instance_number" function.
Also, I don't understand why it keeps looping like that, if under the textbox is shown, I set "showDamage" to 0.

Yeah, I've checked "Debug mode" , and showDamage is always 1, also when it does the "showDamage=0". I don't understand anything, is gamemaker doing something weird here.
 
Last edited by a moderator:
L

leonfook29

Guest
Instance number is used to count the amount of instance of an object that you specified that's in this room, so if it's keep on counting then it would be what you said, multiple instance. My guess is that in some other place there's something that keep making it into 1, so even though you've turn it to 0, the next step it became 1 again and another text box would spawn again.

Try searching for clue on what keep turning it to 1. There's a very nice function in GMS where shift + middle mouse click on the code (like your showDamage)would display all the place that contain that piece of code. It would also helps if you learn how to do debug mode.
 
T

Tchangla

Guest
I've fixed it! I've learned how to use GM debug tool now haha.
I wasn't controlling one of the actions and thus I've made an infinite loop.
Thanks leonfook29!
 
Top