Search code examples
game-maker

How to make an object spawn when a condition is met on game maker


I have been making a game on game maker and i wanted an object to spawn in my room when a certain amount of score is reached. i have tried this by doing:

if global.score >= 10
{
    instance_create(obj_flag);
}

but when i go to run it it says " there is a wrong number of arguments for function instance_create"

It would be much appreciated if some one could help me. Thankyou


Solution

  • I don't know game-maker, but a quick google search shows that instance_create() takes three arguments, hence the error about the wrong number of arguments:

    http://gamedesign.wikidot.com/gamemaker:instance-create

    id = instance_create( x, y, obj );
    
     id = returned instance id
      x = x location to create object
      y = y location to create object
    obj = name of object to create an instance of
    
    instance_create() creates an instance of an object at 
    the specified x/y coordinates. It also returns the instance 
    id of the instance created, which can be put into a variable
    and used to manipulate the instance.
    

    So it looks like the API is requiring you to specify where to create it.