@Paul Thayer,
Sorry about the delay in getting back, it's been a busy few days. It sounds like you got things working and some good advice from IndianaBones so this comment adds little to the discussion other than minor points of clairification. So if you're interested in a bit more info on the topic of variable types feel free to read on, otherwise feel free to ignore this response
--------------------------------------
That's interesting that xprevious didn't work for you, and to be honest I'm not quite sure why that would be. Game maker is
supposed to track three things for both x and y on all objects. When the object is created it stores the initial value of x in xstart, the current value of x in x and the last value of x in xprevious (which is supposed to be set before the begin step action). And you can see the documentation for it at
https://docs.yoyogames.com/source/d...vement and collisions/movement/xprevious.html if you wanted to know more.
But if your x_old works and xprevious doesn't, it's not the end of the world as it's an admittedly minor optimization. As far as the health question, IndianaBones is correct. If you want to know a bit more about this, there are actually 3 types of variables in Game Maker. The first (and most common) is an instance variable. This is just made by picking a keyword and assigning a value to it. (myvar = 3) And as long as you're working in an object or referencing that object you can access that variable (obj_player.myvar).
The second type of variable is called a local variable and is created by adding the keyword var in front of it. (var myvar = 3) Essentially this tells game maker to forget about this variable after the given task has run. So unlike the instance variable if you run a local variable in a script that variable will be forgotten after the script is run and can't be accessed again which is great for keeping memory free when some variables are only used to temporarily hold a calculation.
The last type of variable is a global variable and they are set by appending them to the "global." prefix. (global.myvar = 3) These variables are unique in that once created they can be accessed from anywhere and they never refer to any particular object. This is useful for instance if you had a difficulty setting that you wanted to be accessible to all objects but only needs to be set once. Health is a global variable that game maker studio registers for you when the game starts, so setting health affects health globally and not just for the object you were currently accessing. Now admittedly game maker breaks it's own rules a bit here and uses "globalvar health" to set it up so that health becomes a global var without the global. prefix. Not only is the advised against because it's going to eventually be depreciated, but it creates the exact issue you had. Namely, a variable that isn't recognizable as a global without prior knowledge.