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

GML [SOLVED] Object.coords not accepted? (Acts like object doesn't exist)

Dr_Nomz

Member
I'm trying to use a console to spawn in an object, and if the arguments provided don't have specific coords (x and y aren't sent through the console) it'll spawn at the Character's position instead.

I've used this same type of thing before many times but now here for some reason it acts like the object doesn't exist, even though it clearly does.

The weird thing is it knows that it's own object exists, obj_console, and it'll gladly accept those coords when spawning the item, but not for the player character.

Code:
action number 1
of  Step Event0
for object obj_console:

Unable to find any instance for object index '0' name 'obj_Character'
 at gml_Object_obj_console_StepNormalEvent_1 (line 30) -       instance_create(obj_Character.x,obj_Character.y,obj_1); }
############################################################################################
--------------------------------------------------------------------------------------------
stack frame is
gml_Object_obj_console_StepNormalEvent_1 (line 30)
That's the error I get when I try to use this code:

Code:
      var obj_1 = asset_get_index(console_value(_console,1));
      if(obj_1 > -1){
      instance_create(obj_Character.x,obj_Character.y,obj_1); }
Basically it spawns the object based on it's name in the index, but the coords are the issue here. When I use these, it just throws an error like obj_Character doesn't exist. Any idea why?

This is the console I'm using if it helps:
https://marketplace.yoyogames.com/assets/1356/developer-console
 
A

Annoyed Grunt

Guest
I've used this same type of thing before many times but now here for some reason it acts like the object doesn't exist, even though it clearly does.
Are you 100% sure? Because if an instance of obj_Character does indeed exist, then this is either a bug or there are other factors at play.
 

Dr_Nomz

Member
I just tested it in another object, it worked just fine. Don't know why this won't find the object...

Oh, I tried to use the create event to set the character's position, and it remembered where it was when it was created in the first room, but not the next one.
 

Dr_Nomz

Member
update: I think it's because the stupid console is "disabling" everything, and that for some reason makes it impossible to find the damn thing. Is there any way around this or no?
 
A

Annoyed Grunt

Guest
You'll have to be more specific in what you mean by "disabling" and why the console does it.
 
R

Rukiri

Guest
Does "obj_Character" exist?
I don't see a reason as to why you're getting an error...
 

Dr_Nomz

Member
Eh nevermind, instance_deactivate_all was necessary for the thing to work at all, so I just worked around it by having it create an object that runs the code I need AFTER the console is closed, so it worked out. Thanks for your time though.
 
Top