• 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!

GML Visual Only want to set the variable to 0 one time

J

JakeW

Guest
Hello all! I'm having a bit of difficulty right now. Basically I want a sort of spending currency thing in my game, so to do this I have some code so far, where once a user clicks on a lot it transforms into a building and creates a new instance, and once that instance exists I have it subtract -5 from the score. The only problem is that it keeps subtracting score because that instance exists. Is there a way to only make this portion of code run once and then never again?
 

Dagoba

Member
Make a variable.

Create event:
paid = false;

Step Event:
if (!paid) {
paid = true;
score -= 5;
}
 

Dagoba

Member
Uhm.. I haven't used DnD for like 8 years but I can check.

This code goes to the building object!

Create event:
Control tab > Variables > Pick the most left variable, name it "paid" and set the score to 0.

Step event:
Control tab > Variables > Pick the middle variable, name it "paid", value 0, operation: equal to
Control tab > Other > Start block (the arrow that points up)
Control tab > Variables > Pick the most left variable, name it "paid" and set the score to 1.
Score tab > Score > Pick the top-left score box, set the name new score -5 and tick relative box
Control tab > Other > End block (the arrow that points down).

Done! :) Hope it works.
 
J

JakeW

Guest
Uhm.. I haven't used DnD for like 8 years but I can check.

This code goes to the building object!

Create event:
Control tab > Variables > Pick the most left variable, name it "paid" and set the score to 0.

Step event:
Control tab > Variables > Pick the middle variable, name it "paid", value 0, operation: equal to
Control tab > Other > Start block (the arrow that points up)
Control tab > Variables > Pick the most left variable, name it "paid" and set the score to 1.
Score tab > Score > Pick the top-left score box, set the name new score -5 and tick relative box
Control tab > Other > End block (the arrow that points down).

Done! :) Hope it works.
Awesome, thank you :D
 
Top