• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

problem with spike bomb

P

piksil_demon

Guest
ok, the problem im having is this- when i shoot the spike bomb, it does destroy itself, but it only spawns one spike that goes right. can you tell me whats wrong with my code, and how to properly spawn all 8? p.s. parent is a blank object.
p.p.s. the alarm in the "exploded" is to give it some invincibility frames after spawning

and yes, ill be switching to states soon, im using this as a trial run
Code:
Information about object: obj_spikebomb
Sprite: spr_spikebomb
Solid: false
Visible: true
Depth: 0
Persistent: false
Parent: obj_parent
Children:
Mask:
No Physics Object
Create Event:
execute code:

hp=10

Step Event:
execute code:

if hp <=0{{
instance_create(x,y,obj_spikebomb_exploded) image_angle=0;
instance_create(x,y,obj_spikebomb_exploded) image_angle=45;
instance_create(x,y,obj_spikebomb_exploded) image_angle=90;
instance_create(x,y,obj_spikebomb_exploded) image_angle=135;
instance_create(x,y,obj_spikebomb_exploded) image_angle=180;
instance_create(x,y,obj_spikebomb_exploded) image_angle=225;
instance_create(x,y,obj_spikebomb_exploded) image_angle=270;
instance_create(x,y,obj_spikebomb_exploded) image_angle=295;
}
instance_destroy()}

Information about object: obj_spikebomb_exploded
Sprite: spr_spikebomb_exploded
Solid: false
Visible: true
Depth: 0
Persistent: false
Parent: obj_parent
Children:
Mask:
No Physics Object
Create Event:
execute code:

alarm[0] = room_speed*.1
hp = 10
speed = 10;
direction = image_angle;


Alarm Event for alarm 0:
execute code:

//just here to turn on alarm

Step Event:
execute code:

if alarm[0]=0
{if place_meeting (x,y,obj_player) {global.hp -= 25}
if instance_place (x,y,obj_spikebomb){obj_spikebomb.hp-=25}
if hp<=0 {instance_destroy()}}
 

Roderick

Member
Actually, it's drawing eight spikes that all go right, and are all facing right. Your image_angle has nothing telling what to apply the rotation to, so you're rotating the object that's currently exploding.

image_angle just rotates the image. You also need to set direction to the same angle to control its direction.

If I can revamp your code a bit:

Code:
if hp <=0{{
   for (var i = 0; i < 8; i++)
   {
      var spike = instance_create(x,y,obj_spikebomb_exploded)
      spike.image_angle = i * 45;
      spike.direction = i * 45;
   }
}
instance_destroy()}
 
P

piksil_demon

Guest
Actually, it's drawing eight spikes that all go right, and are all facing right. Your image_angle has nothing telling what to apply the rotation to, so you're rotating the object that's currently exploding.

image_angle just rotates the image. You also need to set direction to the same angle to control its direction.

If I can revamp your code a bit:

Code:
if hp <=0{{
   for (var i = 0; i < 8; i++)
   {
      var spike = instance_create(x,y,obj_spikebomb_exploded)
      spike.image_angle = i * 45;
      spike.direction = i * 45;
   }
}
instance_destroy()}
just so i have an idea of whats going on, what does the strip of code for (var i = 0; i < 8; i++) do?

also, it says theres an unexpected symbol in spike.image_angle = i * 45; and spike.direction = i * 45;
 
Last edited by a moderator:

Bingdom

Googledom
just so i have an idea of whats going on, what does the strip of code for (var i = 0; i < 8; i++) do?

also, it says theres an unexpected symbol in spike.image_angle = i * 45; and spike.direction = i * 45;
(var i = 0; i < 8; i++) This is a 'for' loop

(<statement1> ; <expression> ;<statement2>) <statement3>

This works as follows - First statement1 is executed, then the expression is evaluated and, if it is true, statement 3 is executed. Then statement 2 and then the expression is evaluated again. This loop will continue until the expression is found to be false.
Also, remove the extra brackets. I don't think they are needed ;)

It should be like this
Code:
if hp <=0{
   for (var i = 0; i < 8; i++)
   {
       //Statement 3
       var spike = instance_create(x,y,obj_spikebomb_exploded)
       spike.image_angle = i * 45;
       spike.direction = i * 45;
   }
instance_destroy();
}
 
P

piksil_demon

Guest
(var i = 0; i < 8; i++) This is a 'for' loop



Also, remove the extra brackets. I don't think they are needed ;)

It should be like this
Code:
if hp <=0{
   for (var i = 0; i < 8; i++)
   {
      var spike = instance_create(x,y,obj_spikebomb_exploded)
      spike.image_angle = i * 45;
      spike.direction = i * 45;
   }
instance_destroy();
}
thanks for the explanation. do you know how to fix the "unexpected statement? i just copied and pasted @Roderick's code. its saying the dot is unexpected
 

Bingdom

Googledom
Have you tried the one i just gave you? I believe the problem was the double '{{' after the 'if' statement. ;)
 
P

piksil_demon

Guest
Have you tried the one i just gave you? I believe the problem was the double '{{' after the 'if' statement. ;)
i did. same problem. it says that the dots at spike.image_angle and spike.direction is unexpected.
 

Bingdom

Googledom
Sometimes it might be a bit slow to update on what you have written. If the error persists, try restarting game maker or there might be another error in your code but haven't been triggered yet in the game.
 
P

piksil_demon

Guest
Sometimes it might be a bit slow to update on what you have written. If the error persists, try restarting game maker or there might be another error in your code but haven't been triggered yet in the game.
i see what you mean. now its saying "error in obj_spikebomb, step event, action 1 at line 5, position 14: unexpected symbol in expression
 

Bingdom

Googledom
Unexpected symbol means there might be something like 'var spike ==' or ';;' or '..' accidently placed somewhere in your code, check around line 5 if there is any errors. If you don't fully understand how to read error messages, i would recommending learning how to. They are very important when debugging :) ;)
 
P

piksil_demon

Guest
Unexpected symbol means there might be something like 'var spike ==' or ';;' or '..' accidently placed somewhere in your code, check around line 5 if there is any errors. If you don't fully understand how to read error messages, i would recommending learning how to. They are very important when debugging :) ;)
i know how to read them, i just dont understand why its telling me this

i just copied and pasted the code you edited-
Code:
if hp <=0{
   for (var i = 0; i < 8; i++)
   {
       //Statement 3
       var spike = instance_create(x,y,obj_spikebomb_exploded)
       spike.image_angle = i * 45;
       spike.direction = i * 45;
   }
instance_destroy();
}
i removed the //statement tho
 

Bingdom

Googledom
i know how to read them, i just dont understand why its telling me this

i just copied and pasted the code you edited-
Code:
if hp <=0{
   for (var i = 0; i < 8; i++)
   {
       //Statement 3
       var spike = instance_create(x,y,obj_spikebomb_exploded)
       spike.image_angle = i * 45;
       spike.direction = i * 45;
   }
instance_destroy();
}
i removed the //statement tho
Found it, after looking at it myself, a semicolon has been forgotten after the
'var spike = instance_create(x,y,obj_spikebomb_exploded)'.
 
P

piksil_demon

Guest
Found it, after looking at it myself, a semicolon has been forgotten after the
'var spike = instance_create(x,y,obj_spikebomb_exploded)'.
that fixed it. Thanks again bingdom... uhg... never thought id tell bing thank you lol
 

Bingdom

Googledom
Basically every time you use instance_create, it returns the 'id' of the created instance. So it can be put into a variable and be 'referenced'. Since we got the id of the created instance, we can modify its properties using the 'id'.image_angle and 'id'.direction.

This loop is then being repeated with the variable 'spike' being replaced with a new id every new cycle.
 
P

piksil_demon

Guest
Basically every time you use instance_create, it returns the 'id' of the created instance. So it can be put into a variable and be 'referenced'. Since we got the id of the created instance, we can modify its properties using the 'id'.image_angle and 'id'.direction.

This loop is then being repeated with the variable 'spike' being replaced with a new id every new cycle.
so how do i fix it? every time i pop one spike bomb, they all pop
 
P

piksil_demon

Guest
If it's in a collision event then do this
Code:
with(other) {
    hp-=1;
}
this is in my bullets step event. is this the problem?
Code:
if place_meeting(x,y,obj_parent) {obj_parent.hp -=5
instance_destroy()}
 

Bingdom

Googledom
Try this:
Code:
var collider = instance_place(x, y, obj_parent);
if collider != noone {
    collider.hp -= 5;
    instance_destroy();
}
 

Roderick

Member
Sorry I didn't respond earlier, @piksil_demon. I've been busy the last couple days, and haven't even logged in. I'm glad you got everything sorted.

Thanks for stepping in and helping, @Bingdom.

In case you're wondering, the reason all your objects were exploding is that obj_parent refers to the base object, and every instance of it.

Like my code above, Bing's was finding the id of the specific instance that was colliding, and telling it, and only it, to run the explosion code.

Always remember: Any change you make to an object applies to every single copy of that object that exists. If you only want to change one, you must refer to it by its unique instance id.
 
Top