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

Legacy GM [SOLVED] Saving current coordinates as a constant

D

Dr. B

Guest
Say I want an object to save its initial x or y coordinates into a variable. In the create event, I want to make the variable x0 to equal the x value at that point, where it was created. How would I do that?
 

YoSniper

Member
Simply in the Create Event:
Code:
x0 = x;
y0 = y;
The object's keyword variables like x, y, hspeed, vspeed, gravity, and all of that stuff are set up just prior to the Create Event.
 

TheouAegis

Member
When an instance is created, its coordinates are saved in the variables xstart and ystart. If you want to change the start position of the instance inside its Create Event, you can manually update the variables as well.

xstart = x;
ystart = y;
 
D

Dr. B

Guest
Simply in the Create Event:
Code:
x0 = x;
y0 = y;
The object's keyword variables like x, y, hspeed, vspeed, gravity, and all of that stuff are set up just prior to the Create Event.
I tried that, and it didn't seem to work. Maybe it wasn't working because of some other error I made, but I thought it was because x0 was changing to the current x as the object moved.

When an instance is created, its coordinates are saved in the variables xstart and ystart. If you want to change the start position of the instance inside its Create Event, you can manually update the variables as well.

xstart = x;
ystart = y;
Thanks! xstart is just what I was looking for.
 
Top