Jump to content


Photo

multiple object spawner (help)


  • Please log in to reply
7 replies to this topic

#1 Jezzarb94

Jezzarb94

    GMC Member

  • GMC Member
  • 60 posts

Posted 10 May 2012 - 12:24 PM

i have this code see and it only spawns 1 object I want it to spawn multiple if there is a easy way of doing this please reply
it must spawn from room cords y = 1 because the objects fall from the roof and land on the solid i hope you can help

object_selector=0; 
var i,x1,y1;
i=random(1);
object_selector=round(i);
x1=random(room_width);
y1=random(room_height);
if(object_selector=0)
instance_create(x1,1,obj_tree);
if(object_selector=1)
instance_create(x1,1,obj_object1);

  • 0

#2 NukeTheCat

NukeTheCat

    GMC Member

  • GMC Member
  • 470 posts
  • Version:GM8.1

Posted 10 May 2012 - 12:56 PM

Easy way?

x1 = random(room_width);
y1 = random(room_height);
instance_create(x1,y1,choose(obj_tree,obj_object1)

//with these three lines you can do the same effect
//the choose functions can have more than 2 selections, just so you know
//I also warn you, the choose function also makes the game slightly slower

  • 0

#3 Jezzarb94

Jezzarb94

    GMC Member

  • GMC Member
  • 60 posts

Posted 10 May 2012 - 01:12 PM

Easy way?

x1 = random(room_width);
y1 = random(room_height);
instance_create(x1,y1,choose(obj_tree,obj_object1)

//with these three lines you can do the same effect
//the choose functions can have more than 2 selections, just so you know
//I also warn you, the choose function also makes the game slightly slower

this however dose not create multiple objects how would I do this?
  • 0

#4 Jezzarb94

Jezzarb94

    GMC Member

  • GMC Member
  • 60 posts

Posted 10 May 2012 - 01:13 PM

Easy way?

x1 = random(room_width);
y1 = random(room_height);
instance_create(x1,y1,choose(obj_tree,obj_object1)

//with these three lines you can do the same effect
//the choose functions can have more than 2 selections, just so you know
//I also warn you, the choose function also makes the game slightly slower

this however dose not create multiple objects how would I do this?
  • 0

#5 Jezzarb94

Jezzarb94

    GMC Member

  • GMC Member
  • 60 posts

Posted 10 May 2012 - 01:14 PM

this however dose not create multiple objects how would I do this?




edit: oops double post my bad

Edited by Jezzarb94, 10 May 2012 - 01:15 PM.

  • 0

#6 NukeTheCat

NukeTheCat

    GMC Member

  • GMC Member
  • 470 posts
  • Version:GM8.1

Posted 10 May 2012 - 01:23 PM

Like this?:
obj[0] = obj_tree;
obj[1] = obj_object1
i = irandom(1);
//^put this in the create event

var x1, y1;
x1 = random(room_width);
y1 = random(room_height);

repeat(how_many_times_you_want)
instance_create(x1,y1,obj[i])


Have I got it right?
Wait so how do you want it?

A. Create a single object from a selection multiple times
B. Create multiple random objects.
C. None of the above. Please define.

Edited by Jlm07, 10 May 2012 - 01:28 PM.

  • 0

#7 Jezzarb94

Jezzarb94

    GMC Member

  • GMC Member
  • 60 posts

Posted 10 May 2012 - 01:28 PM

But your code suggests you want a single random object to be created.

Wait so how do you want it?

A. Create a single object from a selection multiple times
B. Create multiple random objects.
C. None of the above. Please define.


create multiple random objects placed through out the map in random spots
  • 0

#8 NukeTheCat

NukeTheCat

    GMC Member

  • GMC Member
  • 470 posts
  • Version:GM8.1

Posted 28 May 2012 - 07:38 PM

Oh, sorry. I didn't know you replied and I totally forgot about this topic.

But should this work then?
instance_create(random(room_width), random(room_height),choose(obj_tree,obj_object1);
//the choose function selects between obj_tree or obj_object1, you can add more objects

if it's still not right, then this?
//CREATE EVENT
array[0] = object0;
array[1] = object1;
array[2] = object2;
//so on, and so forth
amount_of_objects = 3;

[code=auto:0]
// To activate it
instance_create(random(room_width), random(room_height),array[irandom(amount_of_objects)])code]
  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users