1. Hey! Guest! The 35th GMC Jam will take place between November 28th, 12:00 UTC - December 2nd, 12:00 UTC. Why not join in! Click here to find out more!
    Dismiss Notice
  2. 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

Alchemist Table

Discussion in 'Programming' started by Ted Gress, Sep 21, 2018.

  1. Ted Gress

    Ted Gress Member

    Joined:
    Sep 1, 2016
    Posts:
    752
    Hi

    So I have this alchemist table in the corner of my room. What it is supposed to do is when I click on it it takes me to another room, the alchemist lab, When you leave the lab and go back to the main room the lab is supposed to have a timer on it so you can't just hop in and out of th elab. I can go in and out of the lab but the timer isn't working. It isn't there at all. I worked on it all night and can't seem to figure it out.

    ALCHEMIST TABLE OBJECT

    Create Event

    Code:
    alchemist_timer = 0;
    
    Step Event

    Code:
    show_debug_message("Output alchemist timer: " + string(alchemist_timer));
    
    
    if (mouse_check_button_pressed(mb_left) && mouse_x < x+400 && mouse_x > x && mouse_y < y+400 && mouse_y > y)
    {
        
        if (alchemist_timer <= 0)
        {
                alchemist_timer = room_speed*10000;
            
            
                room_set_persistent(FirstLevel, true);
                show_debug_message("Going to room. Saving RoomBeforeStore");
                global.RoomBeforeAlchemist = room;
                room_goto(AlchemistTableRoom);
                draw_set_colour(c_black);   
                alchemist_timer = room_speed*10000;
        }
    }
    
    
    if (alchemist_timer > 0)
    {
        alchemist_timer--;
        instance_create_depth(x, y, 200, HourglassTimer);
        show_debug_message("Alchemist Room TImer: " + string(alchemist_timer));
        draw_text(x,y,string(alchemist_timer/100));
    }
    
    EXIT SIGN OBJECT (to leave the lab and go back to the main room)

    Left Pressed Event

    Code:
    show_debug_message("Going to room before store");
    
    room_set_persistent(FirstLevel, false);
    
    room_goto(global.RoomBeforeAlchemist);
    
    // Only run the un-pause code if we actually un-paused.
    if (global.RoomBeforeAlchemist != -1) {
        global.RoomBeforeAlchemist = -1;
    
    
    }
    
     
  2. TheouAegis

    TheouAegis Member

    Joined:
    Jul 3, 2016
    Posts:
    7,037
    Is your table object set through persistent? If it's not, then when you go back to the room the timer will be reset. if you don't want the table to be persistent, then you will have to make the variable global, which means you'll have to set it first outside the scope of the table, so that you don't reset it accidentally.
     
  3. Kanugane

    Kanugane Member

    Joined:
    Sep 20, 2018
    Posts:
    30
    What about creation code in the room? Every time you get into the room, it will set the time for the object.
     
  4. NightFrost

    NightFrost Member

    Joined:
    Jun 24, 2016
    Posts:
    1,982
    Then the use of table will be barred for a while no matter which other room you come in from. The only good places to set the timer is either when entering the lab if you want to count from last time you entered, or when exiting the lab if you want to count from last time you left.
     
  5. Kanugane

    Kanugane Member

    Joined:
    Sep 20, 2018
    Posts:
    30
    Well, there are other ways but you are correct too and the solution that was given also seems to be the simplistic one. *thumbs up*
     
  6. Ted Gress

    Ted Gress Member

    Joined:
    Sep 1, 2016
    Posts:
    752
    Ok. I tried setting it on the exit sign you click to return to the main game.

    EXIT SIGN

    LeftPressed Event

    Code:
    room_set_persistent(FirstLevel, false);
    global.alchemist_timer = room_speed*100;
    room_goto(global.RoomBeforeAlchemist);
    
    // Only run the un-pause code if we actually un-paused.
    if (global.RoomBeforeAlchemist != -1) {
        global.RoomBeforeAlchemist = -1;
    
    
    }
    
    ALCHEMIST TABLE
    (Step Event)

    Code:
    if (mouse_check_button_pressed(mb_left) && mouse_x < x+400 && mouse_x > x && mouse_y < y+400 && mouse_y > y)
    {
        
        if (global.alchemist_timer <= 0)
        {
    [CODE]draw_self();
    
    if (global.alchemist_timer > 0)
    {
        global.alchemist_timer--;
        instance_create_depth(x, y, 150, HourglassTimer);
        //show_debug_message("Alchemist Room TImer: " + string(global.alchemist_timer));
        draw_text(x,y,string(global.alchemist_timer/100));
    }
    


    room_set_persistent(FirstLevel, true);

    global.RoomBeforeAlchemist = room;
    draw_set_font(Arial_Font_Modified);
    room_goto(AlchemistTableRoom);
    draw_set_colour(c_black);

    }
    }
    [/CODE]
    ALCHEMIST TABLE
    (Draw Event)
     

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