I am using GameMaker Studio 1.4. I have a fireball object, and when it collides with the enemy object, it is supposed to remove 1 (one) from the enemy's life variable.
Here is the code:
Fireball Code
Step Event
if (place_meeting(x,y,obj_enemy)) { // if collision with enemy
with (other) {
other.life-=1; // remove 1 from life
self.start_decay=true; // remove fireball
}
}
Enemy Code
Create
life=1;
isDie=false;
Step Event
if (life<=0) {
isDie=true; // I use a variable because there are other conditions that can also satisfy this
}
[...] // other unnecessary code
if (isDie) {
instance_destroy(); // Destroy self
}
Error Log(s)
___________________________________________
############################################################################################
FATAL ERROR in
action number 1
of Step Event0
for object obj_fireball:
Variable <unknown_object>.<unknown variable>(100017, -2147483648) not set before reading it.
at gml_Object_obj_fireball_StepNormalEvent_1 (line 3) - other.life-=1;
############################################################################################
--------------------------------------------------------------------------------------------
stack frame is
gml_Object_obj_fireball_StepNormalEvent_1 (line 3) ('other.life-=1;')
One thing I notice is that you're using an
otherinside awith(other), which sounds a bit unneccesary.Assuming that the
other.life -= 1is meant for the enemy, and theself.start_decay=trueis for the fireball, then you can remove thewith(other)line (and brackets), keeping the code like this:If you use
with(other), then everything inside thatwith(other)will be targetted towards the 'other' object it's colliding with, in this case, yourobj_enemy.Calling an
otherinside awith(other)will possibly be targetted back towards the fireball, which didn't defined thelifevariable. And that's where your error came from.