Each defence has 2 hp, which I have set with a variable. I have a collision event with the 'enemies' (or a green square) which decreases one 'hp'. In the step event, I have it so if it's lower than 1 'hp', than it will destroy itself.
This works when you place it down in the room, but not if you (the player) place it. I have tested it many times, and it still doesn't work. The enemies collide, die, and nothing happens. The code is down below:
CREATE EVENT
DefenseHealth = 2
STEP EVENT
if DefenseHealth<=1 then instance_destroy()
COLLISION WITH ENEMY EVENT
DefenseHealth= -1
Most of my game is GML, including the movement and making of the towers.
STEP EVENT FOR PLAYER (the tower building)
//Defenses Building (press C!!!!)
if keyboard_check_pressed(ord('C'))
DefenseBuild=1
if keyboard_check_released(ord('C'))
DefenseBuild=0
Score = -10
//But we DON'T won't to build things MID AIR don't we? This is what this code here does.
if Ground=0 // <--- If this is set to one, it will actually make it go in the air.
then DefenseBuild=false // <--- THIS ACTUALLY WORKS!
//But what does DefenseBuild mean? Well, all it does is build your 'Defense' (or in this case, a wall). The variable has it's own set of code below
//stating what it does. All if ACTUALLY does is build the 'Defense' in your current position. This is going to upgraded later on.
if DefenseBuild = 1
then action_create_object(obj_defense,obj_player.x,obj_player.y)Could someone help me? It's essential to have this fixed.
Thanks.
P.S. And yes, that is my code. I've been working on this for a while now.
Edited by Crasher111, 05 November 2012 - 12:52 AM.











