GameMaker How do I make a variable hold it's current value in one instance and have it change in another?

O

OriginalGrim

Guest
I'm having a script basically repeat itself to draw text in a certain way but when I try to have it run the text won't be placed right

create
Code:
_x[0-3]
_X = 0
script
Code:
draw_text(_x[_X], y, "text");
so what happens is the word goes flying across the screen or is stuck in a loop when I program _X to += 1 and I can't think of a way to have it so that each new version of the same script that plays will hold the current _X value and never change.

I basically want it so the script runs and when it determines what _X currently is it changes from the variable (_X) to the number it currently is or holds it as is. In other words how do I make a variables value at the time permanent.
 
Code:
_x[0-3]
What is that? Are you trying to declare an array? What values are you storing in that array? In order for what you want to have happen, you'd need something like this:
Code:
// Create Event
_x[0] = 10;
_x[1] = 15;
_x[2] = 20;
// In GMS 2 you can just do _x = [10,15,20];
_X = 0;
Code:
// Step Event
_X += 1;
_X = _X mod 3; // This'll reset _X back to 0 when it hits the number 3 (you need this so it doesn't try to access _x[3] which has not been created
Code:
// Draw Event
draw_text(_x[_X],y,"text");
 
Top