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

Check the value of a variable in a specific instance

Discussion in 'Programming' started by MoonMonky, Dec 9, 2018.

  1. MoonMonky

    MoonMonky Member

    Joined:
    Dec 9, 2018
    Posts:
    3
    Hi there!

    After reading a lot of thread about similar problem I still can't figure it out how can I check a value of a specific instance and do an action.

    That's my code. It works but it's always goes to Option room and never in Atrio room.

    Code:
        
    
    if mouse_check_button_pressed(mb_left) {            
        if position_meeting(mouse_x, mouse_y, menu_select) {
            if (menu_select.menu_selection == 2)
            {
    room_goto(option);
            }
    
            if (menu_select.menu_selection == 1)
            {
    room_goto(atrio);
            }
    }}
    
    Do you have any idea where I'm wrong? Thanks!
     
  2. TheSly

    TheSly Member

    Joined:
    Jan 16, 2017
    Posts:
    1,001
    Where are you setting the variable menu_selection?
     
  3. MoonMonky

    MoonMonky Member

    Joined:
    Dec 9, 2018
    Posts:
    3
    Thanks for answer and sorry for non-clear question.
    I defined it in "variable definitions" menu of the object. And then I modified the value ("1" and "2") in instances variables.
     
  4. FrostyCat

    FrostyCat Member

    Joined:
    Jun 26, 2016
    Posts:
    4,713
    If you've done any real research on this topic, you should have seen at least one place where I responded demanding that the poster read these articles:
    Given the above, it's not difficult to derive this:
    Code:
    var inst_menu_select = instance_position(mouse_x, mouse_y, menu_select);
    if (inst_menu_select != noone) {
      switch (inst_menu_select.menu_selection) {
        case 1:
          room_goto(atrio);
          break;
        case 2:
          room_goto(option);
          break;
      }
    }
    
     
    MoonMonky likes this.
  5. TheSly

    TheSly Member

    Joined:
    Jan 16, 2017
    Posts:
    1,001
    As Frosty has so elegantly stated, you need to let GM know which menu_select object you are referring to. Even though you did a position_meeting, it doesn't know that you are then referring to that one when accessing the menu_selection variable. Only by using instance_place or instance_position can you obtain the id of the collided object, and then, as his example shows, store the id in a local variable, and then refer to it in order to access that particular instance.
     
    MoonMonky likes this.
  6. MoonMonky

    MoonMonky Member

    Joined:
    Dec 9, 2018
    Posts:
    3
    Thank you!!

    I understand the logic behind that and I'm checking out your guides for newbie, really thank you guys!!
     

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