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

Invalid with reference

I'm getting an "Invalid with reference" on my path_start function call. I think it is referring to the "with" command I use right above path_start. I tried putting in an if clause before the with(inst) and it still has a problem.


The code is here, its a little lengthy but mostly repetitious:

GML:
//////////////DRAW TRAIL OF BATS////////////////////
///////////////////////////////////////////////
draw_trail_of_bats--;

global.spacing_myTimer += 0.001;

if (global.spacing_myTimer > 1.0)
{
    global.spacing_myTimer = 1.0;
}

global.spacing_myTimer2 += 0.001;
if global.spacing_myTimer2 > 1.0
{
    global.spacing_myTimer2 = 1.0;
}
   

global.spacing_myTimer3 += 0.001;
if global.spacing_myTimer3 > 1.0
{
    global.spacing_myTimer3 = 1.0;
}
   

if (draw_trail_of_bats <= 0)
{
    //inst =
    //path from grasslands to forest?
    if (inst == noone)
    {
    inst = instance_create(300, 371, SentryBatWalkMap);
    }
   
    if (inst != noone)
    {
    with (inst)
    {
        path_start(GrasslandsToForestTrail, 5, path_action_stop, 0);
        show_debug_message("Spacing myTimer:" + string(global.spacing_myTimer));
        show_debug_message("Path Position: " + string(path_position));
        path_position = global.spacing_myTimer;
        show_debug_message("Updated path_position" + string(path_position));
        path_end();
    }
    }
    draw_trail_of_bats = room_speed;
   
    //a path from forest to snow
    if (inst2 == noone)
    {
    inst2 = instance_create(378, 354, SentryBatWalkMap);
    }
    if (inst2 != noone)
    {
    with (inst2)
    {
        path_start(ForestToSnowTrailbk, 5, path_action_stop, 0);
        show_debug_message("Spacing myTimer:" + string(global.spacing_myTimer2));
        show_debug_message("Path Position: " + string(path_position));
        path_position = global.spacing_myTimer2;
        show_debug_message("Updated path_position" + string(path_position));
        path_end();
    }
    }
    //open up snow level
//from snow to lava
    if (inst3 == noone)
    {
    inst3 = instance_create(464, 254, SentryBatWalkMap);
    }
   
    if (inst3 != noone)
    {
    with (inst3)
    {
        path_start(SnowToLavaTrailbk, 5, path_action_stop, 0);
        show_debug_message("Spacing myTimer:" + string(global.spacing_myTimer3));
        show_debug_message("Path Position: " + string(path_position));
        path_position = global.spacing_myTimer3;
        show_debug_message("Updated path_position" + string(path_position));
        path_end();
    }
    }


}
And here is the exact error:

___________________________________________
############################################################################################
ERROR in
action number 1
of Step Event0
for object TravelMasterbk:

invalid with reference
at gml_Object_TravelMasterbk_Step_0 (line 54) - path_start(GrasslandsToForestTrail, 5, path_action_stop, 0);
############################################################################################
gml_Object_TravelMasterbk_Step_0 (line 54)
Line 54 points to the first path_start function call.

For the "with(inst)", inst=noone is set in the create event
 

chamaeleon

Member
inst, inst2, and inst3 looks like instance variables. Are they initialized with noone at first? Any chance they retain their values over step events from the instance creation code, with the instance being destroyed at some point, but these instance variables still retaining their not-noone values, hence not allocating a new instance to use with the with statement?
 
inst, inst2, inst3 are instance variables and are initialized with noone at the create event. The instance creation code is done in a step event. I am not sure if they could be being destroyed. Is there a way to check to see if they are properly created by instance_create? I seem to reccall an instance_exists or some sort of function I coudl use instead of doing "if (inst == noone)"
 

Nidoking

Member
Try replacing inst != noone with instance_exists(inst) and see how that works. I suspect the instance you created is being destroyed somewhere and you're not setting the variable back to noone.
 
Try replacing inst != noone with instance_exists(inst) and see how that works. I suspect the instance you created is being destroyed somewhere and you're not setting the variable back to noone.
So it came back with the following error:


instance_exists argument 1 incorrect type (undefined) expecting a Number (YYGI32)
at gml_Object_TravelMasterbk_Step_0 (line 50) - if (instance_exists(inst))
I don't know what this error means. Why is it expecting a number?
 
I'm really curious. Do you use these instance variables anywhere else for any other purpose?
Interesting point. I changed the variable names to trail_inst, trail_inst2, and trail_inst3 so I know for a fact that they would be exclusive and I still get the same error about it expecting an instance id. Almost as if they aren't being created maybe?

(EDIT)

So instance_create is creating an object. I think the "with" might be unnecessary.

Basically I want to create a sprite object that follows a predefined path. But it has to be repeat and do multiple objects. My code did that I know there are other ways, I'm not sure of how to implement them if somebody could help me that would be great!
 
Last edited:

TsukaYuriko

☄️
Forum Staff
Moderator
Interesting point. I changed the variable names to trail_inst, trail_inst2, and trail_inst3 so I know for a fact that they would be exclusive and I still get the same error about it expecting an instance id. Almost as if they aren't being created maybe?
Variables that don't exist will throw an "unknown variable" error, not "incorrect type". The latter is thrown because you passed a value of type undefined to it while it expects a number (an instance ID or object ID).

So instance_create is creating an object.
No, it's creating an instance. Says it right in the name. There's a difference.


Basically I want to create a sprite object that follows a predefined path.
On the subject of the differences between instances and objects, a "sprite object" is not something that exists.

There are objects and there are instances.
There are objects that have a sprite assigned, which will be assigned to the sprite_index of all instances created of it by default.
There are instances that have a sprite assigned to their sprite_index.

However, there are no sprite objects (and no sprite instances, either).


Regarding the error message you posted, inst has a value of undefined when it shouldn't. This means that you're assigning undefined to it somewhere in your code, as this is not a value variables have without external influence. This could be due to reading out of bounds of a data structure, or trying to access an element of a data structure that doesn't exist, which will return undefined. If you are then assigning the return value of that to inst, its value will be undefined.

Put some breakpoints in your code at key locations related to inst and trace back exactly where this happens. Periodically check the value of inst while stepping through your code in debug mode shortly before the error message appears and find out when it is set to undefined.

Basically I want to create a sprite object that follows a predefined path. But it has to be repeat and do multiple objects. My code did that I know there are other ways, I'm not sure of how to implement them if somebody could help me that would be great!
Use an array instead of numbered variables. This way, you can iterate over the array in a loop and execute the same loop for each element of the array, with the elements being instances.
 
Top