1. Hello Guest! It's with a heavy heart that we must announce the removal of the Legacy GMC Archive. If you wish to save anything from it, now's the time! Please see this topic for more information.
    Dismiss Notice

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

Discussion in 'Programming' started by Peej4321, Jan 4, 2019.

Tags:
  1. Peej4321

    Peej4321 Member

    Joined:
    Nov 9, 2018
    Posts:
    14
    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?
     
  2. Rob

    Rob Member

    Joined:
    Jul 12, 2016
    Posts:
    707
    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!!?
     
  3. Peej4321

    Peej4321 Member

    Joined:
    Nov 9, 2018
    Posts:
    14
    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.
     
  4. RefresherTowel

    RefresherTowel Member

    Joined:
    Jul 13, 2016
    Posts:
    1,219
    That's not the entire code. Post ALL relevant code, including how the platform knows the player is on it, etc.
     
  5. TheouAegis

    TheouAegis Member

    Joined:
    Jul 3, 2016
    Posts:
    7,119
    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?
     
  6. Relic

    Relic Member

    Joined:
    Jun 27, 2017
    Posts:
    734
    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.
     
  7. samyak

    samyak Member

    Joined:
    Jul 19, 2016
    Posts:
    93
    Did you try this -- if instance_exists(o_player) { . ...code...}
     
  8. Peej4321

    Peej4321 Member

    Joined:
    Nov 9, 2018
    Posts:
    14
    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.
     
  9. Peej4321

    Peej4321 Member

    Joined:
    Nov 9, 2018
    Posts:
    14
    I almost just completely figured out how to make it all work properly, too.
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice