That draw event makes no sense. You don't want a for loop, you don't even need an if statement in it.
Try something like this:
First, in whatever object you want, probably the one that the hp relates to, initialize the hp (I'm gonna go with the global variable method, because you already started that way:
Then, in the dog object, your code is fine:
Then finally, in that draw event, just use
You don't have to convert it to a string unless you're gonna combine it with other strings.
Now, on the topic of why that "for" was wrong:
For loops are used when you want to repeat the same code block a certain amount of times in ONE STEP.
So if you have a variable called HP and you want to increase it five times, you would do something like this:
Code:
for (var i = 0; i<5; i++){
HP+=1;
}
That might look a bit confusing, so here's a rundown:
The for loop takes 3 "arguments", so to speak. They are all separated with semicolons (
.
The first "argument" is actually a variable that you want to initialize, usually a counter variable. That's the
i variable in the above code.
I initialized it as
var i = 0. The var is there to convey to game maker that this is a temporary variable, i.e. one that will no longer exist after this code is run.
The second "argument" is the expression that gets checked. That's
i<5 in our case. The for loop checks the validity of the expression before running the code. Then, if the expression is true, it runs the code (in our case,
HP+=1;). Then it checks the validity of the expression again, and if it's true, it runs the code again. This goes on and on until the expression is false. When it's false, it goes on to do the code after the for loop.
The third "argument" is, in our case, increasing the counter variable. Usually, this is what you do with it.
i++ just means "increase the variable i by 1 every time the loop runs". In simple terms,
i++ is shorthand for
i+=1 (not exactly, but that's the essential function it has here).
I'm sorry this got so wordy! Let me know if you need any more help or if I didn't explain something very well.