GameMaker How to select an enemy to attack

M

MrTholl

Guest
GMS2 Trying to selct one enemy 3.png GMS2 Trying to selct one enemy 3.png As you can see when I attack an enemy it attacks them both. If I don't select an enemy at the start it will produce an error. When I kill them both it only gives me xp for one enemy.
 

TheouAegis

Member
It's the same image lol.

If you're using the variable health, don't.
If you're doing something like oEnemy.hp-=10 then you need to make sure the part on the left is an instance ID, not an object ID.
 
M

MrTholl

Guest
hahaha it upladed the same image for ome reason.
The left of what?
 
M

MrTholl

Guest
if enemy1_obj.enemy_selected = 1
enemy1_obj.enemy1_hp = enemy1_obj.enemy1_hp-global.player_attack
This is in the step of an object called attack_obj.
 

TheouAegis

Member
Yeah, you're referencing instances by their object ID, not their instance ID. That's a big no-no.

with enemy1_obj if enemy_selected enemy1_hp-=global.player_attack;
 
M

MrTholl

Guest
How will I check if an enemy is selected in the attack_obj?
 

Relic

Member
Like how TheouAegis has suggested. In the attack obj, run a with command which will run the code for each instance of obj enemy. Each instance of obj enemy will know if it was selected or not by checking enemy_selected
 
Top