Legacy GM [Solved] Unknown error after importing project from GM8.1 to GM:S 1.4

Hello, I started getting errors in my pedestrian object after importing my game from GM 8.1 to GM:S 1.4. I don't get what this error is saying at all or what's causing it, I didn't make any changes other than adding physics to the car object.
___________________________________________
##########################################################################################
FATAL ERROR in
action number 2
of Step Event0
for object obj_ped:

Unable to find any instance for object index '103985'
at gml_Object_obj_ped_StepNormalEvent_2 (line 10) - if(state == 0 and instance_exists(myGuide)){
##########################################################################################
--------------------------------------------------------------------------------------------
stack frame is
gml_Object_obj_ped_StepNormalEvent_2 (line 10)

Here's the code in the script object if it would help

Code:
///AI Core - state 0: walking

///Health
if(Health <= 0){
    state = 2;
}

if(state == 0 and instance_exists(myGuide)){
    
    injured = false;

    ///Walk towards guide
    if(walk == true){
        mp_potential_step( myGuide.x , myGuide.y , walkSpeed , false );
    }
    
    ///Stop if close to guide
    if(distance_to_object(myGuide) < 5 and !state == 2){
        walk = false;
    }else{
        walk = true;
    }
    
    ///Run over
    if(instance_exists(obj_car)){
        nearestCar = instance_nearest( x , y , obj_car)
        if(instance_exists(nearestCar)){
            nearestCar = instance_nearest( x , y , obj_car);
                if(collision_circle( x , y , 20 , obj_car , true , true )){
                    if(nearestCar.speed > 1 and collision_circle( x , y , 5 , obj_car , true , true )){
                        state = 2;
                    }
                }
            }
    }

    ///Bullet collision   
    if(collision_circle( x , y , 10 , obj_bullet , false , false )){
        if(global.blood == true){
            instance_create( x , y , obj_bloodHit);
        }
        Health -= obj_player.bulletDamage;
    }
        
    
}
 

Tthecreator

Your Creator!
It's just that 103985 is a very weird number for an instance id or an object index. Can you get the "id" and the "object_index" of the myGuide object for me?
 

Tthecreator

Your Creator!
The thing about instance_exists is that you can give it two values.
I'll quote the manual:
"This function can be used in two ways depending on what you wish to check. You can give it an object_index to check for, in which case this function will return true if any active instances of the specified object exist in the current room, or you can also supply it with an instance id, in which case this function will return true if that specific instance exists and is active in the current room."

The error message means that GM thinks you are supplying the instance_exists function an object_index. However, the object_index 103985 doesn't exist (or at least that is my guess).
 
The thing about instance_exists is that you can give it two values.
I'll quote the manual:
"This function can be used in two ways depending on what you wish to check. You can give it an object_index to check for, in which case this function will return true if any active instances of the specified object exist in the current room, or you can also supply it with an instance id, in which case this function will return true if that specific instance exists and is active in the current room."

The error message means that GM thinks you are supplying the instance_exists function an object_index. However, the object_index 103985 doesn't exist (or at least that is my guess).
What I don't get is why it worked in GM8 but not GMS. I thought checking if an instance exists was the same in both. Also, the guide is never meant to despawn unless the ped despawns
 

NightFrost

Member
Have your instance either display its ID on screen or debug message it to output during creation. You can then compare it to what the error message throws out and confirm if your variable is holding the correct value. I agree what seems to be happening here is: instance_exists first tries to find an instance holding the ID value set into myGuide variable, but fails to find any. It then assumes you must be referring to an object instead. But there is no object with that ID either, so it throws an error. Your instance might as well exist, but your check is receiving wrong value(s). If there's only one instance of that object ever, you could check through the object ID instead of using instance ID saved to a variable.
 
Have your instance either display its ID on screen or debug message it to output during creation. You can then compare it to what the error message throws out and confirm if your variable is holding the correct value. I agree what seems to be happening here is: instance_exists first tries to find an instance holding the ID value set into myGuide variable, but fails to find any. It then assumes you must be referring to an object instead. But there is no object with that ID either, so it throws an error. Your instance might as well exist, but your check is receiving wrong value(s). If there's only one instance of that object ever, you could check through the object ID instead of using instance ID saved to a variable.
Thanks, but what is an object ID? Is it just the name of the object? I'm just now noticing that both the car guides and ped guides are acting weird. Is there a reason why it's 💩💩💩💩ing up in GMS when it worked fine in GM8? I know they are different engines but I thought the basics of GML would be the same.
 

TheouAegis

Member
The object ID is the object_index. It's not the name of the object -- that's just an enumerator for the object_index. But what NightFrost is saying is if your game will only have one pedestrian guide and only one vehicle guide active at any time, then you could just use if instance_exists(oPed_Guide) or whatever your guide is called.

Since this is GM1.4 we're dealing with here, go into the Global Game Settings and turn on Short-Circuit Evaluation.

What's the code you have that sets myGuide? Where is that code called?

103985 is not an odd instance ID at all, it's a typical id to be expected if 3985 instances have been created since the start of the game.

Does the error come up immediately? Or does it come up after you've done something in the game?

I didn't make any changes other than adding physics to the car object.
Do you mean "physics" as just a lazy term for movement code you wrote from scratch, or do you mean you are using the built-in Physics engine? If you are using the engine, then you need to enable the room to use Physics. And if you've enabled the room to use Physics, certain variables stop behaving correctly, making it doubly important to see how you assigned myGuide.
 
The object ID is the object_index. It's not the name of the object -- that's just an enumerator for the object_index. But what NightFrost is saying is if your game will only have one pedestrian guide and only one vehicle guide active at any time, then you could just use if instance_exists(oPed_Guide) or whatever your guide is called.

Since this is GM1.4 we're dealing with here, go into the Global Game Settings and turn on Short-Circuit Evaluation.

What's the code you have that sets myGuide? Where is that code called?

103985 is not an odd instance ID at all, it's a typical id to be expected if 3985 instances have been created since the start of the game.

Does the error come up immediately? Or does it come up after you've done something in the game?


Do you mean "physics" as just a lazy term for movement code you wrote from scratch, or do you mean you are using the built-in Physics engine? If you are using the engine, then you need to enable the room to use Physics. And if you've enabled the room to use Physics, certain variables stop behaving correctly, making it doubly important to see how you assigned myGuide.
Thanks for replying, I just ran the game without Short-Circuit Evaluation for fun, but the issue seems to be fixed. I don't know what it even is, maybe whatever it does doesn't happen in GM 8.1? I tried to look it up but I couldn't find a straight answer.
 

Bart

WiseBart
Your issue isn't properly fixed yet.

If you don't get the error anymore with short-circuit evaluation turned on it just means you never end up in a situation where state == 0.
Because of the short-circuit evaluation the instance_exists(myGuide) check is never executed.

By the look of it, it seems that GM seems to consider 103985 to be an object index, while every value > 100000 is supposed to be an instance id.
Did you place myGuide in the room via the Room Editor or did you create it in code?
If it's the former you could try to remove it from the room and adding it back again (make sure it's created at the right time).
If it's the latter the best thing to do is to add some debug code and see what comes out, as mentioned in the previous posts.
 
Your issue isn't properly fixed yet.

If you don't get the error anymore with short-circuit evaluation turned on it just means you never end up in a situation where state == 0.
Because of the short-circuit evaluation the instance_exists(myGuide) check is never executed.

By the look of it, it seems that GM seems to consider 103985 to be an object index, while every value > 100000 is supposed to be an instance id.
Did you place myGuide in the room via the Room Editor or did you create it in code?
If it's the former you could try to remove it from the room and adding it back again (make sure it's created at the right time).
If it's the latter the best thing to do is to add some debug code and see what comes out, as mentioned in the previous posts.
It fixed itself when I turned short circuit evaluation off.
 

TheouAegis

Member
It fixed itself when I turned short circuit evaluation off.
What he means is something is going on when your state is 0, or rather when state is not 0. The value of state for some reason has a direct correlation to the value and/or existence of myGuide. Toggling short-circuit evaluations just tells GM to ignote half of that conditional. Consider the following:
Code:
if A and B { C; }
if A or B { D; }
if A xor B { E; }
Now, in GM8, conditions A and B would both be checked 3 times. But with short-circuit evaluations, only A would be checked 3 times, whereas B only needs to be checked once, thus potentially speeding up the code slightly. Let's look at each line and see how short-circuit evaluations may or may not help it.

if A and B { C; }
At what point will C be performed? When A and B are both true, and only when A and B are both true. So if A is true, we need to check the value of B. What if A is false? In GM8, that doesn't matter -- we still need to check the value of B. This is just a waste of the CPU's time, especially if either A or B are complex conditionals which take a lot of time to calculate. So with short-circuit evaluations, if A is false, B never gets checked. This means given a completely random distribution of A and B, we only need to check B 50% of the time. We can lower this % even more, but more on that later.

if A or B { D; }
At what point will D be performed? When either A or B are true, even if both are true. So if A is false, we still need to check the value of B. Again, given a completely random distribution of A and B, we only need to check B 50% of the time with short-circuit evaluations.

if A xor B { E; }
At what point will E be performed? When either only A or only B is true. Short-circuit evaluations don't help us here, as both conditions must be checked every time. If A is true, then we need to check if B is false. If A is false, then we need to check if B is true. This is why I said B would need to be run at least once in the code above.

You could do your own derivation of short-circuit evaluations in GM8, but it's more lines of code People tend to like slower, shorter code over faster, verbose code when the gains are so miniscule.
Code:
if A
   if B
      C;

if !A {
   if B
      D;
}
else
   D;

if A xor B
   E;
 
What he means is something is going on when your state is 0, or rather when state is not 0. The value of state for some reason has a direct correlation to the value and/or existence of myGuide. Toggling short-circuit evaluations just tells GM to ignote half of that conditional. Consider the following:
Code:
if A and B { C; }
if A or B { D; }
if A xor B { E; }
Now, in GM8, conditions A and B would both be checked 3 times. But with short-circuit evaluations, only A would be checked 3 times, whereas B only needs to be checked once, thus potentially speeding up the code slightly. Let's look at each line and see how short-circuit evaluations may or may not help it.

if A and B { C; }
At what point will C be performed? When A and B are both true, and only when A and B are both true. So if A is true, we need to check the value of B. What if A is false? In GM8, that doesn't matter -- we still need to check the value of B. This is just a waste of the CPU's time, especially if either A or B are complex conditionals which take a lot of time to calculate. So with short-circuit evaluations, if A is false, B never gets checked. This means given a completely random distribution of A and B, we only need to check B 50% of the time. We can lower this % even more, but more on that later.

if A or B { D; }
At what point will D be performed? When either A or B are true, even if both are true. So if A is false, we still need to check the value of B. Again, given a completely random distribution of A and B, we only need to check B 50% of the time with short-circuit evaluations.

if A xor B { E; }
At what point will E be performed? When either only A or only B is true. Short-circuit evaluations don't help us here, as both conditions must be checked every time. If A is true, then we need to check if B is false. If A is false, then we need to check if B is true. This is why I said B would need to be run at least once in the code above.

You could do your own derivation of short-circuit evaluations in GM8, but it's more lines of code People tend to like slower, shorter code over faster, verbose code when the gains are so miniscule.
Code:
if A
   if B
      C;

if !A {
   if B
      D;
}
else
   D;

if A xor B
   E;
I get it now, thanks! But I just found out it just takes longer for the error to occur or makes it less likely to happen without short circuit evaluation than with it. I'm fiddling around with the code but every time I fix something, something else starts causing trouble.
 
Top