Reputation: 1
This code does destroy the object when its health reaches 0 but it won't add 5/7 to the global.xp variable.
if rotem_hp > 1 and shop_13 = 0
{
rotem_hp = rotem_hp -1
}
else
{
if rotem_hp > 1 and shop_13 = 1 rotem_hp = rotem_hp -1.5
if rotem_hp < 1 and shop_4 = 0 global.xp = global.xp + 5 instance_destroy()
if rotem_hp < 1 and shop_4 = 1 global.xp = global.xp + 7 instance_destroy()
}
if (rotem_hp > 1 and global.shop_13 = 0)
{
rotem_hp = rotem_hp -1
}
else if (rotem_hp > 1 and global.shop_13 = 1)
{
rotem_hp = rotem_hp -1.5
}
else if (rotem_hp < 1 and global.shop_4 = 0)
{
global.xp = global.xp +5
instance_destroy()
}
else if (rotem_hp < 1 and global.shop_4 = 1)
{
global.xp = global.xp +7
instance_destroy()
}
else
{
//do nothing
}
if rotem_hp > 1 and global.shop_13 = 0
{
rotem_hp = rotem_hp -1
}
if rotem_hp > 1 and global.shop_13 = 1
{
rotem_hp = rotem_hp -1.5
}
if rotem_hp < 1 and global.shop_4 = 0
{
global.xp = global.xp +5
instance_destroy()
}
if rotem_hp < 1 and global.shop_4 = 1
{
global.xp = global.xp +7
instance_destroy()
}
I will appreciate any efforts to answer my question.
Upvotes: 0
Views: 201
Reputation: 1
Okay, for everyone who encountered the same problem as me:
I finally managed to solve the issue, the problem was that I used:
if rotem_hp > 1
{
rotem_hp = rotem_hp -1
}
Instead of:
if rotem_hp >= 1
{
rotem_hp = rotem_hp -1
}
So when "rotem"'s health reachd exactly 1, the code didnt know what to do since I told it to do stuff when >1 and <1, this was such a stupid problem and I cant believe I wasted more than a few minutes to solve it, I will now go hide in the corner of my room full with shame. goodbye.
Upvotes: 0
Reputation: 1777
When you write
if rotem_hp < 1 and shop_4 = 0 global.xp = global.xp + 5 instance_destroy()
if rotem_hp < 1 and shop_4 = 1 global.xp = global.xp + 7 instance_destroy()
it means
if rotem_hp < 1 and shop_4 = 0
{
global.xp = global.xp + 5
}
instance_destroy()
if rotem_hp < 1 and shop_4 = 1
{
global.xp = global.xp + 7
}
instance_destroy()
so last if
will newer checked bacause the object will be already destroyed.
You need use curve braces for define if
scopes.
You can write like this:
if rotem_hp < 1 and shop_4 = 0
{
global.xp += 5
instance_destroy()
}
if rotem_hp < 1 and shop_4 = 1
{
global.xp += 7
instance_destroy()
}
or if you want only one line for one 'if'
if rotem_hp < 1 and shop_4 = 0 { global.xp += 5; instance_destroy(); }
if rotem_hp < 1 and shop_4 = 1 { global.xp += 7; instance_destroy(); }
Upvotes: 2