Jump to content


Photo

overspawn problem!


  • Please log in to reply
6 replies to this topic

#1 GreenhornGames

GreenhornGames

    GMC Member

  • GMC Member
  • 730 posts
  • Version:GM8

Posted 25 May 2012 - 05:44 PM

i have a problem with this code:

if score=20
{
instance_create(x,y,obj_bird_ctrl)
};

if score = 30
{
instance_create(x,y,obj_rocket_ctrl)
} ;

if score = 50
{
instance_create(x,y,obj_meteor_ctrl)
} ;

if score=70
{
instance_create(x,y,obj_meteor_ctrl)
};


each of these objects which are suppose to spawn are object spawners. here is one of them:


//Create event
alarm[0]=300



//Alarm 0 event

instance_create(random_range(view_xview,view_wview),
view_yview,obj_meteorite);

//this is for below

alarm[0]=300+random(200) //This will make it a random number between 10 and 20

The problem is, once the score is reached for one spawner, it creates 20 of objects! and it should spawn only one! whats the problem?
  • 0

#2 Manfrex

Manfrex

    GMC Member

  • GMC Member
  • 132 posts
  • Version:GM8

Posted 25 May 2012 - 05:51 PM

The problem is that it is creating one instance every step as long as the score is e.g 20. You need to do like this:
if (score = 20) && (!instance_exists(obj_bird_ctrl)) {
instance_create(x,y,obj_bird_ctrl);
}

That will only spawn one object, since it checks if one already exists. :)
  • 1

#3 GreenhornGames

GreenhornGames

    GMC Member

  • GMC Member
  • 730 posts
  • Version:GM8

Posted 25 May 2012 - 06:01 PM

yes but i already have one of those spawn objects and i want to have one more
  • 0

#4 Manfrex

Manfrex

    GMC Member

  • GMC Member
  • 132 posts
  • Version:GM8

Posted 25 May 2012 - 06:06 PM

yes but i already have one of those spawn objects and i want to have one more


Oh okay, well, as it is right now, it will spawn one object every step as long as the score is 20. You need to do something so that it only creates the object once, when the score turns 20. Perhaps something like this?
if (score = 20) && (objectHasSpawned = 0) {
objectHasSpawned = 1;
instance_create(x,y,obj);
}

  • 0

#5 GreenhornGames

GreenhornGames

    GMC Member

  • GMC Member
  • 730 posts
  • Version:GM8

Posted 25 May 2012 - 06:16 PM

for what object is the "objectHasSpawned" variable for?
  • 0

#6 Manfrex

Manfrex

    GMC Member

  • GMC Member
  • 132 posts
  • Version:GM8

Posted 25 May 2012 - 06:24 PM

for what object is the "objectHasSpawned" variable for?


Any object really, but the easiest one would be the one that you have the spawning code in. :)
  • 0

#7 GreenhornGames

GreenhornGames

    GMC Member

  • GMC Member
  • 730 posts
  • Version:GM8

Posted 25 May 2012 - 06:41 PM

i dont know why, but when i do it like this:

if (score = 20) && instance_exists(obj_rocket_ctrl) && (global.objectHasSpawned = 0) {
global.objectHasSpawned = 1;
instance_create(x,y,obj_rocket_ctrl);
}

it says that the variable doesnt exist and i can only fix it by putting the obj_rocket_ctrl in the room. this object is the spawner of obj_rocket.
funny thing is that it spawns normally when i put it in room from beginning.


EDIT: the first code didnt fix it :( it still spawns awful lot of them. what if i put the whole thing into create event?

Edited by GreenhornGames, 25 May 2012 - 06:45 PM.

  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users