Legacy GM Bomb Limit

H

Heat4Life

Guest
So I want to Limit the Bombs on my In-Game... For example: when there is 5 Bombs on the room, I want It to get destroyed... So currently I have this on my Bomb Object:

Create Event:
Code:
alarm[0] = 100;
Step Event:
Code:
if(place_meeting(x, y, obj_wall)) {
    x = random(room_width);
    y = random(room_height);
}

if(place_meeting(x, y, obj_bomb)) {
    x = random(room_width);
    y = random(room_height);
}
Alarm 0 Event:
Code:
bomb = instance_create(random(room_width), random(room_height), obj_bomb);

bomb = (x = random(room_width));
bomb = (y = random(room_height));
... so How to achieve this? Thanks!

All answers would be greatly appreciated! :D
 
T

TDSrock

Guest
Whenever a bomb is created(so the obj_bomb create event) increase a global variable by one.

Before creating a obj_bomb check the global variable.

Whenever a bomb is deleted(obj_bomb destroy event) decrease the global variable by one.

This should be the bottom line here, I won't provide you with any code. This should be simple enough to figure out along with this explanation.
 
A

Aura

Guest
First of all, you have faulty syntax in the Alarm event.

Code:
bomb = (x = random(room_width));
bomb = (y = random(room_height));
That code does nothing. Because you're overwriting the instance ID with either true (1) or false (0) as x = random(room_width) is an expression in your case and you're basically checking if x is equal to random position on the horizontal plane.

You don't need that code at all IMO. Since you're already creating the bomb at a random position.

Second of all, you shouldn't use the bomb object to create the instances of the same. Use a control object instead and make sure that you have less than 5 instances of the bomb object in the room by using instance_number().

Code:
if (instance_number(obj_Bomb) < 5) {
   //Create a bomb instance at a random position
}
 
H

Heat4Life

Guest
That code does nothing. Because you're overwriting the instance ID with either true (1) or false (0) as x = random(room_width) is an expression in your case and you're basically checking if x is equal to random position on the horizontal plane.

You don't need that code at all IMO. Since you're already creating the bomb at a random position.
Yeah but If I remove the Instance variable then It doesn't do what I like It to do to be honest...

EDIT: Oh yeah, I forgot that the instance_create function got this x, y position stuff lol :p

Use a control object instead
That's what I did...
 
Last edited by a moderator:
Top