1. Hey! Guest! The 36th GMC Jam will take place between February 27th, 12:00 UTC - March 2nd, 12:00 UTC. Why not join in! Click here to find out more!
    Dismiss Notice
  2. NOTICE: We will be applying a Xenforo update on Tuesday 25th of February. This means that from approximately 10:00 to 14:00 BST the forums will be offline (or possibly longer). Sorry for the inconvenience! Official Announcement here.

[Solved] Can you make an Alarm who's timer transfers between rooms?

Discussion in 'Programming' started by relic1882, Jan 20, 2020.

  1. relic1882

    relic1882 Member

    Joined:
    Apr 5, 2018
    Posts:
    32
    I'm working on a clock system for my project that involves a day/night cycle. I'm using shaders to fade the screen from bright to dark and back using a global timer. At night, the lights come on and the paths are lit up the way I want while coming back to day the lights shut off. Everything is great on that aspect.

    I'm using an alarm to hold the timer for 30 seconds in this code (although it will be changed to minutes) and by doing that is keeps my full day and full night as long as I want before transitioning back to the opposite.

    My question is am I able to somehow keep an alarm timer continuous between different rooms, or do I have to make some more global variables and do this manually?


    Code:
    if (!pauseTimerTriggered)
    {
        global.timeOfDay += ((0.08 / room_speed) * global.clockDirection);    //slow increase in time of day
    
        if global.timeOfDay >= 0.94                //if time of day is dark,
        {
            pauseTimerTriggered = true;            //trigger pausing the clock calculations for fading
            alarm_set(0, room_speed * 30);        //set alarm for XX seconds
            global.timeOfDay = 0.94
            global.clockDirection *= -1;
        }
        if global.timeOfDay <= .01                //same as above, but pause for full day setting
        {
            pauseTimerTriggered = true;
            alarm_set(0, room_speed * 30);
            global.timeOfDay = 0.01
            global.clockDirection *= -1;
        }
        
    }
    The alarm is simply releasing the trigger to continue the clock again.

    pauseTimerTriggered = false;

    Any thoughts? Thank you!
     
  2. O.Stogden

    O.Stogden Member

    Joined:
    Jul 25, 2018
    Posts:
    248
    If the object that has and triggers the alarm is persistent, then it will carry on between rooms.
     
  3. relic1882

    relic1882 Member

    Joined:
    Apr 5, 2018
    Posts:
    32
    I checked the persistent box for the lighting controller the and child room object.

    Is the alarm resetting because I have the object in all the rooms? Do I have to start the game with one object and it will go from room to room?

    I thought I had to have my light controller in each room that gets loaded. Please enlighten me. I'm starting to feel that I'm not understanding a persistent object like I should.

    Thanks for the reply!
     
  4. O.Stogden

    O.Stogden Member

    Joined:
    Jul 25, 2018
    Posts:
    248
    Persistent objects carry between rooms, so you should have it placed in the room you first visit that needs it, and then it will exist no matter what room you enter, until you destroy it.

    So yes, just place it once.

    And yes, the alarm will be resetting if it's been placed in several rooms.
     
  5. TsukaYuriko

    TsukaYuriko Q&A Spawn Camper Forum Staff Moderator

    Joined:
    Apr 21, 2016
    Posts:
    1,989
    When using a global variable and instances, if you have instances of this object in multiple rooms, the time will first reset for every new room (because the new instance will reset the time), then start counting faster (because now you have two instances counting up). Time will tick thrice as fast in the third room that has the instance, and so on.

    You don't even need to use a global variable, though, because persistent instances - and any variable that belongs to them - persist between rooms. The variable can be under instance scope.
     
  6. relic1882

    relic1882 Member

    Joined:
    Apr 5, 2018
    Posts:
    32
    So I've corrected it thanks to you guys and your help. I've started the lighting object controller on the first screen. The other problem was that when I made it persistent, it wasn't working, but I found out it creates instances of other objects upon creation that had to be persistent as well or it wouldn't count properly when switching rooms

    Overall, I made two different lighting counters. One for outdoors where the darkness for time of day changes from 0 to 1, using that time scale as the alpha setting in the lighting controller for the fade, very slowly before locking into full bright or dark using an alarm.

    The other keeps the time of day going, but controls lighting indoors by keeping the area dark except for the light sources.

    I create the persistent outdoor timer and destroy the persistent indoor timer when entering a room that goes from indoor to outside, and it goes the other way around when going from outside to inside.

    So far so good. Thanks again for the help!
     

Share This Page