Alchemist Table

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;


}
 

TheouAegis

Member
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.
 
K

Kanugane

Guest
What about creation code in the room? Every time you get into the room, it will set the time for the object.
 

NightFrost

Member
What about creation code in the room? Every time you get into the room, it will set the time for the object.
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.
 
K

Kanugane

Guest
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.
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*
 
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)
 
Top