GMS 2 [SOLVED] One of my objects suddenly is unable to find the instance of another

Peej4321

Member
I have a "player" object and a platform it can stand on, and when it does, said platform falls downwards. In order to make the player stick to the falling ground as it falls, it has to instantly go at the same speed (be moved down the same amount of pixels each frame) as the platform. This is done by the platform reading the y coordinate of the player using "[player object name].y". This works fine, until the moving platform falls beneath a stationary one, and the player object stands still on the stationary platform. At this point, for an unknown reason, the moving platform becomes unable to read the y coordinate of the player, saying that it can't find an instance of it in the error that it raises: "Unable to find any instance for object index '3' name '[player object name]'". I think it goes without saying that there is only one instance of the player object in the room, and it definitely still exists when the error is raised. Why is this happening? Is it something to do with the index thing in the error message?
 

Rob

Member
Can you show the relevant code and the full error message?

Post the code and error message like this please:

Code:
Why isn't my code working!!?
 

Peej4321

Member
Can you show the relevant code and the full error message?

Post the code and error message like this please:

Code:
Why isn't my code working!!?
Code:
Code:
you_obj.y += 9;
Error:
Code:
Unable to find any instance for object index '3' name 'you_obj'
Like I said, it does actually work, but only for a bit.
 

TheouAegis

Member
Also, you said the error happens after the player falls with a platform onto a stationary platform. That means, probably, something is going on upon the collision with the stationary platform. Also, if the player is on a falling platform and collides with a stationary platform, what happens to the falling platform? well it goes without saying that there is only one player object in the room, it does not go without saying that there is still a player of it in the room. how do you know you did not accidentally destroy the player instance hrough some error in your code?
 

Relic

Member
Object index ‘3’ Is just referring to the you_obj’s position in the resource tree (all assets are just integers behind the scenes).

I agree with Theou that something must happen that destroys the player. Are the stationary platforms dangerous? Do you have code that destroys the player when inside another platform or the player gets moved outside of the room?

Having the moving platform force the player down 9 pixels, possibly into the stationary platform starts off some series of events leading to instance_destroy() of your player.
 

samyak

Member
I have a "player" object and a platform it can stand on, and when it does, said platform falls downwards. In order to make the player stick to the falling ground as it falls, it has to instantly go at the same speed (be moved down the same amount of pixels each frame) as the platform. This is done by the platform reading the y coordinate of the player using "[player object name].y". This works fine, until the moving platform falls beneath a stationary one, and the player object stands still on the stationary platform. At this point, for an unknown reason, the moving platform becomes unable to read the y coordinate of the player, saying that it can't find an instance of it in the error that it raises: "Unable to find any instance for object index '3' name '[player object name]'". I think it goes without saying that there is only one instance of the player object in the room, and it definitely still exists when the error is raised. Why is this happening? Is it something to do with the index thing in the error message?
Did you try this -- if instance_exists(o_player) { . ...code...}
 

Peej4321

Member
So I just tried putting "if (instance_exists())" in front of the part that moves the player down, and, lo and behold, the player object is destroyed. My bad. But it's not actually entirely to do with the moving platform, but I knew that it wouldn't have happened without the moving platform, which is why I was confused. The player object gets destroyed by a hazard, but it's not close enough to it to have been destroyed normally. It must be something to do with the platform moving it downwards that somehow moves it sideways into the hazard. The player object doesn't get destroyed when there is no hazard nearby, but now I'm working on making it not get dragged through the floor.

Thanks for all the help, and getting me to think about how I can solve this problem.
 
Top