• 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!

instance_place returning -4

L

Laurent

Guest
Hey guys what's up :)

So the idea is that the player click on a square in the interface, so he can assign a number to that specific square.
There are different squares, and in each of them there is an instance of the object "num_btn_obj"

When you click on a square, the game has to save the unique instance id of that square, so the number chosen by the player goes only in that specific square.

This is the code in the click event of the object

///Create ask_input_obj
with (ask_input_obj) {instance_destroy()};
instance_create(0,0,ask_input_obj);
number_id = instance_place(mouse_x,mouse_y,num_btn_obj);
number_id is a global variable that temporarily store the id of the clicked square.

The "ask_input_obj" draw a question for the user asking for the number to put in the square.
This object also has a "press enter" event with this code in it

number_id.num = 1;
instance_destroy();
To semplify things and testing purposes i assigned 1 to the "num" variable in the button object, regardless of the player input.

everythings works until i try giving a number and press ENTER


___________________________________________
############################################################################################
FATAL ERROR in
action number 1
of Key Press Event for <Enter> Key
for object ask_input_obj:

Pop :: Execution Error - Variable references invalid object (-4).<unknown variable>
at gml_Object_ask_input_obj_KeyPressed_ENTER_1 (line 1) - number_id.num = 1;
############################################################################################



Do you guys have any clue? Thanks in advance :)

Laurent
 
L

Laurent

Guest
Hey Aura, thanks for the fast reply.

How is that possible that the click event trigger if there is no instance of the button object there?
 
A

Aura

Guest
That might happen due to a variety of reasons. For instance, you might want to use instance_position() instead, since instance_place() requires both the objects to have valid collision masks; object running the code and object that you're looking for an instance of.

Currently your code is not clear at all and tells nothing about what you intend to do. For instance, I can't understand if that code is put a Mouse event or the Create event; or why you are destroying and re-creating the instance. Please explain in detail what you want to do, what you're doing and why you're doing that.
 

jo-thijs

Member
It looks like you want to get the id of the executing instance.
For this, you should use:
number_id = id;

instead of:
number_id = instance_place(mouse_x,mouse_y,num_btn_obj);

The reason your code is returning noone, is probably because instance_place does not return the id of the executing instance.
 
L

Laurent

Guest
ahhhh :D

Thanks both of you, the problem was what jo-thijs said :)

I appreciate your help a lot!!
 
A

Aura

Guest
Glad you fixed the issue. Please set the status of the topic as solved. To do that, go to Edit Title/Thread Tools >> Edit Title >> Set the topic prefix to Solved.
 
Top