GameMaker Check previous state of variable?

N

nicktheslayer95

Guest
I have an enemy that jumps, in a top-down game, so when the enemy is drawn it uses a fake Z axis "slimeZ", to show that height.

Now, I want to check for when the slime lands, and spawn particles at that time. I'm trying to find if there's a way to say "if slimeZ = 0 and slimeZprevious = 1, instance_create(objParticle)"

xprevious and yprevious are built into GML, but there doesn't seem to be a customVariable.previous of any kind, so how else can I achieve this?
 
P

ParodyKnaveBob

Guest
Howdy, nick,

You've pretty much answered your own question. Whereas GM has x and xprevious, and y and y previous, you just follow suit. Make customvar and customvarprevious. (I tend to use customvar_prev myself, but w/e.) Oh, and unofficially last I checked, GM sets the "previous" variables to the same value as the regular variables in the Begin Step Event, thus you might as well set your "previous" variables there, too, eh? ~shrug~

I hope this helps,
Bob
 
N

nicktheslayer95

Guest
Hold on, let me get this right.
In Begin Step I can set "slimeZprevious = slimeZ", then call it in Step? That's genius.
 

TheouAegis

Member
Begin Step: xprevious and yprevious get updated; alarms count down; timelines count up; and other stuff happens
Step: Nothing special here unless you say so
End Step: Instances are moved; collisions are checked; animations are handled; and other stuff happens

Using all 3 step events is sometimes critical. Even if you don't use built-in variables and so not need to worry about End Step auto-actions, the End Step is still useful because it's run after everything else has run the Step. And Begin Step is useful because it's run before everything else has run the Step (or alarms or timelines or anything else).
 
Top