2

Now I'm making an endless runner where objects are spawned in front on me randomly.

I was told to make a spawnController and globalController object, so I did. Then this code should be put in the controller under step event

if(tick = 32)
{
 tick = 0;
 instance_create(room_width,room_height,random(spike,groundBlock));
 instance_create(room_width,irandom_range(0,room_height-32));
}
tick += 1;

Is there anything wrong with it because i get an error, which is:

In object spawnController, event Step, action 1 at line 4: Wrong number of arguments to function or script.
Rob
  • 4,927
  • 4
  • 26
  • 41
user1947331
  • 47
  • 2
  • 7

3 Answers3

2
instance_create(room_width,irandom_range(0,room_height-32));

The error messages in GM can sometimes be a bit unclear.. But in this case it was pretty clear. It goes about this line. And one of the scripts has too few arguments. Either irandom_range or instance_create you forgot an argument.

irandom_range takes two arguments to make a random number, so that is correct.

instance_create however takes 3 arguments: x,y position and the object from which you wish to create an instance. You're simply missing that argument (and the error tells you that). I think that is a typo as you do it correctly in the creation above.

Manual about instance_create

paul23
  • 8,799
  • 12
  • 66
  • 149
  • First you say I'm missing a third argument but then you say I think it is a typo and I did it correctly. So your saying the code is right? – user1947331 Feb 13 '14 at 16:48
  • Uh, I said you did have the correct use of the function instance_create in the use above line 4 (in line 3)... Did you by any chance just copy code? see edit for a link to the manual – paul23 Feb 15 '14 at 17:29
  • Yes I copied code but modified it so it uses my sprites. – user1947331 Feb 16 '14 at 20:22
  • @user1947331 Then I would suggest you read the the (online) documentation that comes with gamemaker - posted a relevant link above already. We're not here to make the program for you. – paul23 Feb 17 '14 at 15:26
  • yes I know, I was just asking about the error. And I did look at the documentation and it did not help in terms of my error. – user1947331 Feb 17 '14 at 22:13
  • Well I explained the error quite clearly: you used 2 arguments and did not provide the object from which to create an instance.. If you do not understand above line I suggest you read up the documentation more. – paul23 Feb 17 '14 at 22:44
1

You have a syntax error here:

instance_create(room_width,irandom_range(0,room_height-32);

There's no closing parentheses or a 3rd argument.

DiegoSalazar
  • 13,361
  • 2
  • 38
  • 55
0

One thing that stood out to me is that you used random instead of choose. Im not sure there is a difference in this situation, but choose allows you to list as many arguments you want. But the other thing as was pointed out, was that your missing the object you want the 4th life to create. You need to specify what object you want it to make.

instance_create(room_width, irandom_range(0,room_height-32), OBJECT);
Rob
  • 4,927
  • 4
  • 26
  • 41