1. Hey! Guest! The 36th GMC Jam will take place between February 27th, 12:00 UTC - March 2nd, 12:00 UTC. Why not join in! Click here to find out more!
    Dismiss Notice
  2. NOTICE: We will be applying a Xenforo update on Tuesday 25th of February. This means that from approximately 10:00 to 14:00 BST the forums will be offline (or possibly longer). Sorry for the inconvenience! Official Announcement here.

Please help, collision crashing game.

Discussion in 'Programming' started by limpet76, Jan 23, 2020.

  1. limpet76

    limpet76 Member

    Joined:
    Jan 23, 2020
    Posts:
    7
    Haven't been doing gamemaker too long, however I have a problem with my coding. This is the code for the enemy:
    STEP
    "if collision_line(x,y,obTimb.x,obTimb.y,obWall,1,0)
    {
    move_snap(0,0)
    }
    else
    {
    mp_potential_step(obTimb.x,obTimb.y,4,1)
    }"

    Then this is the code on the player:
    COLLISION WITH ENEMY

    "hp -= 5
    audio_play_sound(sndShooting,1,0)
    if hp <= 0
    {
    global.gameEnd = true
    obTimb.visible = false
    room_goto(roomGameOver)
    audio_play_sound(sndPlayerHit,1,0)
    }"

    I am getting an ERROR That looks like this whenever an enemy kills the player:

    "FATAL ERROR in
    action number 1
    of Step Event0
    for object obZomb:

    Unable to find any instance for object index '0' name 'obTimb'
    at gml_Object_obZomb_StepNormalEvent_1 (line 1) - if collision_line(x,y,obTimb.x,obTimb.y,obWall,1,0)"

    Any help would be appreciated
     
  2. chamaeleon

    chamaeleon Member

    Joined:
    Jun 21, 2016
    Posts:
    1,107
    1. Define and explain what a killed player is as implemented in your code.
    2. Ensure you have an instance of an object in the room before you attempt to use any of its variables or properties.
    3. Stop using object names as if they are instances, use instances instead. Just because you can does not mean it is a very good practice, and you need to understand the implications.
     
  3. limpet76

    limpet76 Member

    Joined:
    Jan 23, 2020
    Posts:
    7
    Sir you have confused me.
     
  4. limpet76

    limpet76 Member

    Joined:
    Jan 23, 2020
    Posts:
    7
    A killed player is when HP <= 0, as stated. The player will then go invisible and switch to a game over room.
     
  5. TsukaYuriko

    TsukaYuriko Q&A Spawn Camper Forum Staff Moderator

    Joined:
    Apr 21, 2016
    Posts:
    1,989
    As the error message says - Unable to find any instance for object index '0' name 'obTimb' - there is no instance of obTimb. You're trying to access the variables of an instance of it. It doesn't exist -> crash. You're probably destroying it somewhere and the code that needs it to exist isn't checking whether it exists via instance_exists beforehand.
     
  6. robproctor83

    robproctor83 Member

    Joined:
    Sep 30, 2019
    Posts:
    296
    Well, your missing some code or something because the error is saying that obTimb is missing but I don't see in the code where you may be removing it. my suggestion, simply:

    "if instance_exists(objTimb) && collision_line(x,y,obTimb.x,obTimb.y,obWall,1,0)"
     
  7. limpet76

    limpet76 Member

    Joined:
    Jan 23, 2020
    Posts:
    7
    Problem is, my players not being destroyed, checked for that in the code first.
     
  8. limpet76

    limpet76 Member

    Joined:
    Jan 23, 2020
    Posts:
    7
    Ends up doing this
    FATAL ERROR in
    action number 1
    of Step Event0
    for object obZomb:

    Unable to find any instance for object index '0' name 'obTimb'
    at gml_Object_obZomb_StepNormalEvent_1 (line 7) - mp_potential_step(obTimb.x,obTimb.y,4,1)
     
  9. TsukaYuriko

    TsukaYuriko Q&A Spawn Camper Forum Staff Moderator

    Joined:
    Apr 21, 2016
    Posts:
    1,989
    If the player exists, this error message will not be shown. Therefore, it either does not exist yet or does not exist anymore - which of the two is the case is not something we can tell you without seeing all relevant code.

    objTimb is not obTimb. This should have raised a compiler error. Are you using an ancient version of GameMaker with the game option to treat uninitialized variables as 0, by any chance?
     
  10. limpet76

    limpet76 Member

    Joined:
    Jan 23, 2020
    Posts:
    7
    I saw objTimb and changed it to obTimb in the code dw. Using V1.4 of GameMaker
     
  11. robproctor83

    robproctor83 Member

    Joined:
    Sep 30, 2019
    Posts:
    296
    Oh yea I had a typo my bad... But yea, anywhere you use obTimb you need to check if it exists, BUT I have a feeling you are accidentally deleting it somehow without realizing, or you have some race condition going on where you are destroying things to go to the next room but you are destroying the obTimb before the object that it's inside of and so it's triggering an error.
     
  12. limpet76

    limpet76 Member

    Joined:
    Jan 23, 2020
    Posts:
    7
    Anyway I can link the game file so people can have a look?
     
  13. TsukaYuriko

    TsukaYuriko Q&A Spawn Camper Forum Staff Moderator

    Joined:
    Apr 21, 2016
    Posts:
    1,989
    No real need for that - output debug messages whenever instances of obTimb are created or destroyed, and also output whenever the game thinks it doesn't exist. This alongside some break points in debug mode should lead you to where you're accidentally destroying it.
     
    robproctor83 and chamaeleon like this.

Share This Page