GMS 2 [SOLVED] Persistent object disappearing

Discussion in 'Programming' started by Joky, Jun 2, 2019.

  1. Joky

    Joky Member

    Joined:
    May 21, 2019
    Posts:
    24
    So I have an object that is persistent and when switching rooms and then back it disappears.

    Any solutions?
     
  2. HeWhoShallNotBeNamed

    HeWhoShallNotBeNamed Member

    Joined:
    Nov 9, 2018
    Posts:
    61
    A few questions up front. Do you have any code in your object that would cause it to destroy itself? Are your rooms different sizes? Is it disappearing when you go from the room its created in to a second room, or only when you go back to the first room from a second room? One quick check I'd do is putting in a show_debug_message in a room start or destroy event to make sure its actually disappearing and something else isn't happening.
     
  3. Joky

    Joky Member

    Joined:
    May 21, 2019
    Posts:
    24
    no destruction no different room sizes when I go from first room to second and then back it disappears
     
  4. HeWhoShallNotBeNamed

    HeWhoShallNotBeNamed Member

    Joined:
    Nov 9, 2018
    Posts:
    61
    You're going to need to post some code: anything in your persistent object that pertains to changing rooms and any code in other objects that handles room changes or effects your persistent object.
     
  5. Joky

    Joky Member

    Joined:
    May 21, 2019
    Posts:
    24
    Step:
    Code:
    if (kids = 5)
    {
        object_set_visible(obj_kid,false);
        obj_cash.cash = obj_cash.cash + 15
        kids = 6
        alarm[2] = room_speed * 2
    }
    Alarm:
    Code:
    kid = 0
    room_goto(rm_earnings)
    Button That Can Be Clicked In 2ND Room To Go Back:

    Code:
    if mouse_check_button_pressed(mb_left) && position_meeting(mouse_x, mouse_y, obj_green) && (obj_greenbutton.dead = 0)
    {
          room_goto(rm_office)   
          obj_cash.x = 3092
          obj_cash.y = 512
          obj_kid.kids = 0
          obj_kid.kid = 0
          obj_greenbutton.good = 0
          obj_greenbutton.bad = 0
          audio_play_sound(snd_knockknock,1,false)
          audio_resume_sound(snd_music)
          
          obj_kid.alarm[0] = room_speed * 2
     
  6. Azenris

    Azenris Member

    Joined:
    Oct 30, 2016
    Posts:
    62
    Do you have code that deactivates things?
     
  7. Joky

    Joky Member

    Joined:
    May 21, 2019
    Posts:
    24
    what do you mean?
     
  8. HeWhoShallNotBeNamed

    HeWhoShallNotBeNamed Member

    Joined:
    Nov 9, 2018
    Posts:
    61
    Alright, so you set obj_kid to be invisible if the kids variable equals 5, but nowhere in your code (at least the code you've provided) is it set to visible again. You've reset the kids variable to 0, but that doesn't automatically change visibility back after its set to false just because kids no longer equals 5.
     
  9. Joky

    Joky Member

    Joined:
    May 21, 2019
    Posts:
    24
    Forget to add this XD



    Code:
    if (kids = 5)
    {
        object_set_visible(obj_kid,false);
        obj_cash.cash = obj_cash.cash + 15
        kids = 6
        alarm[2] = room_speed * 2
    }
    
    if (kids < 5 && !kid = 0 && obj_door.door = "open")
    {
    obj_kid.visible = true
    }
    
    if (kids > 5 || kid = 0 || obj_door.door = "closed")
    {
    obj_kid.visible = false
    }
    
     
  10. Joky

    Joky Member

    Joined:
    May 21, 2019
    Posts:
    24
    any solutions?
     
  11. Joky

    Joky Member

    Joined:
    May 21, 2019
    Posts:
    24
    I fixed it! I just instead of making obj_kid persistent so the kid and kids variables stay I just put them all in an object that was already persistent.
     

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