• 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!
  • Hello [name]! Thanks for joining the GMC. Before making any posts in the Tech Support forum, can we suggest you read the forum rules? These are simple guidelines that we ask you to follow so that you can get the best help possible for your issue.

Legacy GM Incorrect parenthesis error

C

CerebralThief

Guest
I am trying to spawn enemies on a randomly generated terrain using a tileset but it says I need a parenthesis where I already have one.

Code:

// Randomly Spawn enemy
if (!instance_exists(obj_enemy))
{
instance_create(random(tileset_main, 0, 64, 64, 64, x, y, 100000.x),random(tileset_main, 0, 64, 64, 64, x, y, 100000.y),obj_enemy);
}


It says I need a parenthesis right after 100000.x but I can't tell why. If I put one there or anywhere else it doesn't fix it. Please help.
 
D

David Berkompas

Guest
I don't know 1.4, but that statement(random) in GMS2 only takes 1 parameter, and you're passing 8.

instance_create (
random(tileset_main, 0, 64, 64, 64, x, y, 100000.x),
random(tileset_main, 0, 64, 64, 64, x, y, 100000.y),
obj_enemy);

Dave
 

johnwo

Member
As @David Berkompas noted; The random function only takes one argument.

Try with something along the lines of:

Code:
instance_create(irandom(room_width),irandom(room_height),obj_enemy);
Or if you want to create obj_enemy in the room with x/y coordinates snapped (to, for example, 64):

Code:
instance_create(irandom(room_width) div 64,irandom(room_height) div 64,obj_enemy);
Using irandom instead of random ensures that you get whole numbers (1, 2, 3, 4, and so on), as opposed to random, which may return a real number (integers, irrational numbers, fractions, etc.).
 
Also, apart from the random() function problem as mentioned above, when you write 100000.x, it looks like you are trying to use 100000 as an instance id.

If you want GMS to interpret 100000 as an instance id, you need to surround it with parentheses : (100000).x

Otherwise GMS will see it as a number, and think it is weird that you are putting ".x" after it.
 
Top