• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

Day/Night cycle somehow works unstable

Level 10
Joined
May 24, 2016
Messages
339
The topic name desctibe my problem pretty well. Sometimes it works, sometimes dont


JASS:
function Trig_Day_Actions takes nothing returns nothing
local integer i = 6 
local real r = GetFloatGameState(GAME_STATE_TIME_OF_DAY)

if r == 6.00 then
set Day = true 
set Night = false
else
set Day = false 
set Night = true


endif


endfunction


function InitTrig_Day takes nothing returns nothing
    set gg_trg_Day = CreateTrigger(  )
    call TriggerRegisterGameStateEvent(gg_trg_Day, GAME_STATE_TIME_OF_DAY, EQUAL, 6.00)
    call TriggerRegisterGameStateEvent(gg_trg_Day, GAME_STATE_TIME_OF_DAY, EQUAL, 18.00)
  //  call TriggerAddCondition( gg_trg_Day, Condition( function Trig_Day_Conditions ) )
    call TriggerAddAction( gg_trg_Day, function Trig_Day_Actions )
endfunction

I tried using A LOT of methods (game state Event) mentioned on the hiveworkshop. And all of them work completely unstable throughout many tests.
 

Uncle

Warcraft Moderator
Level 73
Joined
Aug 10, 2018
Messages
7,875
I remember having issues with this in the past, it's likely because Reals are imprecise and/or the increments used to increase the "time of day" Real skips those specific values that you're checking for.

Anyway, here's a working solution:
vJASS:
library TimeOfDay initializer Init

    globals
        private timer DayNightTimer
        boolean Day = false
        boolean Night = true // Set one of these to true by default
    endglobals

    private function CheckTimeOfDay takes nothing returns nothing
        local real time = GetFloatGameState(GAME_STATE_TIME_OF_DAY)

        if time >= 6.00 and time < 18.00 then
            if Night then
                set Day = true
                set Night = false
                call DisplayTextToPlayer(Player(0), 0, 0, "Day")
            endif
        elseif Day then
            set Day = false
            set Night = true
            call DisplayTextToPlayer(Player(0), 0, 0, "Night")
        endif
    endfunction

    private function Init takes nothing returns nothing
        set DayNightTimer = CreateTimer()
        call TimerStart(DayNightTimer, 0.10, true, function CheckTimeOfDay)
    endfunction

endlibrary
This will check the time of day once every 0.10 seconds and adjust the Day/Night booleans as needed. It will only trigger once per cycle.
 
Last edited:
Level 24
Joined
Feb 27, 2019
Messages
833
Might be related or not since "unstable" doesnt really say much but I experienced crashes from time of day events with exact time such as 06.00. Solution for me was to add a wait of 0.10 seconds before any more actions, lel.

EDIT: Thanks to someone called Pyrogasm I was forced to double check my experience which took several minutes of my precious time and led me to the conclusion that changing time of day speed upon the event the in-game time becomes ... causes a crash which is what I was experiencing.
 
Last edited:
Top