GMS 2 [SOLVED] Variables not applying!?

Discussion in 'Programming' started by Drago the Shinigami, Jul 13, 2019 at 7:08 PM.

Tags:
  1. Drago the Shinigami

    Drago the Shinigami Member

    Joined:
    Jan 20, 2019
    Posts:
    27
    Hi,

    So, recently I almost fixed my door problem, and ran into another problem: the variables set up in the instance are not working: they're going back to the object defaults.

    For example, when I change dest_x and dest_y to 671 and 828 respectively, they are still act like their default values (0) when I run the game.

    The object has a parent object, if that helps.
     
  2. Catan

    Catan Member

    Joined:
    Jun 20, 2016
    Posts:
    619
    Is this all the information you are giving us? How are you setting those variables up? Can you provide the code or are you doing this by using the variables button in the room editor?
     
  3. Drago the Shinigami

    Drago the Shinigami Member

    Joined:
    Jan 20, 2019
    Posts:
    27
    When changing it I use the variables button in the room editor.

    The object in question is obj_SC_Door0, and its parent is Door_Template, which has the default values of 0.
     
  4. Doulos

    Doulos Member

    Joined:
    Jun 8, 2019
    Posts:
    15
    Do you set these variables in your Create case?
     
  5. Annoyed Grunt

    Annoyed Grunt Member

    Joined:
    Jun 20, 2016
    Posts:
    110
    Variables set within the room editor are set before the create event fires, so it will 'reset' them.
     
    Catan likes this.
  6. Drago the Shinigami

    Drago the Shinigami Member

    Joined:
    Jan 20, 2019
    Posts:
    27
    I set the default variables in the Variable Definitions section of the Object creator, not the Create event...
     
  7. Catan

    Catan Member

    Joined:
    Jun 20, 2016
    Posts:
    619
    Yes but do you overwrite them by any chance in the create event? As said, the create event is executed after the variables are assigned from variable definitions
     
  8. Drago the Shinigami

    Drago the Shinigami Member

    Joined:
    Jan 20, 2019
    Posts:
    27
    This is all that is in the create event:
    Code:
    /// @description freeze
    image_speed = 0;
    audio_group_load(sfx0);
    Nowhere in any of the code are dest_x or dest_y overwritten.
     
  9. Doulos

    Doulos Member

    Joined:
    Jun 8, 2019
    Posts:
    15
    In your original, you seem to be assuming these variables are 0 because of the behavior?
    Since it seems like you are doing everything right, could you prove they are?
    Would you put a write of the variables to your screen in your draw event to see what they are?
    It sounds like something else might be wrong.
     
  10. Catan

    Catan Member

    Joined:
    Jun 20, 2016
    Posts:
    619
    Ok then how do you check that the variables you set in the definition are in fact ignored?

    You should try to output their values using a show_debug_message in create and possibly in a key press event to get some insight
     
  11. Drago the Shinigami

    Drago the Shinigami Member

    Joined:
    Jan 20, 2019
    Posts:
    27
    Sorry, I should have described what happens when I run it. Instead of my character being moved to (671, 828), she is moved to (0,0).
     
  12. Catan

    Catan Member

    Joined:
    Jun 20, 2016
    Posts:
    619
    How do you move it?
     
  13. Drago the Shinigami

    Drago the Shinigami Member

    Joined:
    Jan 20, 2019
    Posts:
    27
    I have a complex object called FADE_CAM that controls inter-room movement and fading transitions. Here is the code:

    create:
    Code:
    /// @description set stuff.
    global.a = 0.0;
    global.c = c_black;
    global.newX = 0;
    global.newY = 0;
    global.newRoom = noone;
    global.GETREADYTORUMBLE = false;
    show_debug_message("Stuff has been set!!")
    draw GUI:
    Code:
    if(global.MovingRooms){
    draw_set_alpha(global.a);
    draw_set_color(global.c);
    draw_rectangle(0,0,1023,768, false);
    draw_set_alpha(1.0)
    }
    step:
    Code:
    if(global.MovingRooms)
    {
        if(global.GETREADYTORUMBLE == true)
        {
            global.a = 1.0;
            global.c = c_white;
            global.GETREADYTORUMBLE = false;
        }
        if(global.a >= 1.0)
        {
            global.a = 1.0;
            increment *= -1;
            room_goto(global.newRoom);
            Magna.x = global.newX;
            Magna.y = global.newY;
        }
        global.a += increment;
        if(global.a <= 0)
        {
            increment *= -1;
            global.MovingRooms = false;
            Magna.control_lock = false;
            global.c = c_black;
        }
    }
     
  14. Drago the Shinigami

    Drago the Shinigami Member

    Joined:
    Jan 20, 2019
    Posts:
    27
    Also, I should mention that this is the code for collision with the player for the door:

    Code:
    if(!opening && !active)
    {
        active = true;
        opening = true;
        audio_play_sound(sfx_door0, 100, false);
        image_speed = 1;
        global.newX = dest_x;
        global.newY = dest_y;
        global.newRoom = dest_room;
    }
     
  15. Doulos

    Doulos Member

    Joined:
    Jun 8, 2019
    Posts:
    15
    is FADE_CAM persistent? or is it getting created in each room?
     
  16. Drago the Shinigami

    Drago the Shinigami Member

    Joined:
    Jan 20, 2019
    Posts:
    27
    It is persistent, sorry for not mentioning that.
     
  17. Doulos

    Doulos Member

    Joined:
    Jun 8, 2019
    Posts:
    15
    I think you need to draw these two to your screen somewhere and watch it.
    global.newX
    global.newY

    Also show_debug_message() door's variables; opening, active, dest_x, dest_y.

    This seems like something you have to watch happening real time.

    Edit: I am guessing
    if(!opening && !active)
    is coming out false.
     
  18. Drago the Shinigami

    Drago the Shinigami Member

    Joined:
    Jan 20, 2019
    Posts:
    27
    Well, I just tried drawing the variables global.newX, global.newY, dest_x, and dest_y, and it turns out that after the door is created, dest_x and dest_y are put as 0.
     
  19. Doulos

    Doulos Member

    Joined:
    Jun 8, 2019
    Posts:
    15
    I just reproduced putting an object with a variable default changed and it definitely works for me.
    drawing the variable value.

    Could you...
    Add a new variable to the door, draw that out too.
    put a few random doors in your 1st convenient-est room so you seem them all right away.
    set that value of each instance to something different via the room as normal.

    Tell us what you see?
     
  20. Catan

    Catan Member

    Joined:
    Jun 20, 2016
    Posts:
    619
    Then you are resetting those variables somewhere in the code of the door probably. The don't change by themselves, try using the search feature to see where exactly you are doing it
     
  21. Drago the Shinigami

    Drago the Shinigami Member

    Joined:
    Jan 20, 2019
    Posts:
    27
    I adjusted the display so that there is a variable that determines the height of the display, and it is different for all 3 doors. However, it just displayed two 0's
     
  22. Drago the Shinigami

    Drago the Shinigami Member

    Joined:
    Jan 20, 2019
    Posts:
    27
    I FIGURED IT OUT!!

    It was because I didn't click the "override variable" button in the Variable Definitions for the object obj_SC_Door0!
     
    Catan likes this.
  23. Doulos

    Doulos Member

    Joined:
    Jun 8, 2019
    Posts:
    15

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