• 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!
  • Hello [name]! Thanks for joining the GMC. Before making any posts in the Tech Support forum, can we suggest you read the forum rules? These are simple guidelines that we ask you to follow so that you can get the best help possible for your issue.

Question - Code [SOLVED] Step event and update of instance position

M

MrFox

Guest
Hello,

From the documentation we can read this in the Objects Events chapter:

note that the step event is executed just before instances are put in their new positions
I've made a simple test and don't find a correct result. Can you help me understand why?

On an object available on a room, I've done the following:

On the Create event:

Code:
x= 0;
speed = 10;
And on the Step event:

Code:
catched_x = x;
And on the Draw event:

Code:
draw_text(10, 10, string("X: ") + string(catched_x));
speed = 0;
I was expecting to have "X: 0" as result but instead get "X: 10".

So, is the help manual not up to date or is it an issue with my test or is it a bug?
 

Nocturne

Friendly Tyrant
Forum Staff
Admin
The Step Event in that quote refers to the WHOLE event category, Begin, Step and End, not just the main step event. If you do the check in the Begin Step event then it will behave as you expect (or should!). I'll look at making this clearer in the manual...
 
M

MrFox

Guest
@Nocturne ,

I've tested to move the catch of the x value to the Begin Step but I get the same result. Also, if it must apply to the whole event category, I am expecting to find x equal to 0 in the Begin Step, Step or End Step and only find it equal to 10 in the next events like Pre Draw. Is it not that there is juste a mistake in the manual and that we must read "just after" and not "just before"?
 
M

MrFox

Guest
@Nocturne,

In fact after more testing it seems that step event is well running just before calculation of coordinates. I don't know why my test is not correct.

This is a screenshot of my new test:

 

gnysek

Member
Speed is applied after step event, while writing x+=10 in step event changes position immediately. Now it depends that you remembered x position before or after writing x += 10 :)
 
M

MrFox

Guest
After.

Purpose of all this testing is about using collision_line to detect if an high speed moving object is going from front of another object to back without entering in collision with it. I was testing a line between previous position and actual position but as the modifications of coordinates are done after step event I was doing it wrong. I must test a line between actual position and position once modifications of coordinates are done.
 

gnysek

Member
So, it is obvious that if you write "value = value +2" it will be larger in next line, as GMS is not pushing variables to "later change" no matter that this is "x" or another value.

But speed, hspeed, vspeed are special values, which changes x/y values after step event.
Also gravity, friction changes above after too.

A draw event happens after step event usually, so it will have already changed values.
 
M

MrFox

Guest
I guess that if I want to do a collision check on the coordinates that I will have at the Draw event it is the necessary to do it on Pre Draw event if I use special variables like speed?
 
Unless it has changed between Studio 1 and 2, speed/hspeed/vspeed/etc... Are applied to an instance between Step and End Step, so you'll be able to do the appropriate calculations in the End Step Event.
 
M

MrFox

Guest
I now better understand why during step event xprevious = x and yprevious = y.
 
Top