Is this a bug or am I at fault?

Hello,

I'm looking to implement a feature where in the evening, the colour of the game is inverted (using invert) and to do this I'm checking if datetime.hour >= 20. My code looks like this..

on load do
    night = false
    if datetime.hour >= 20 then
        invert
        night = true
    end
end

on update do
    if night == true then
        if datetime.hour < 20 then
            invert
            night = false
        end
    end
end

However, every time the player move or acts, the invert is toggled regardless of time. I'm not sure if there's an issue in my logic that I'm not seeing, or if the web player doesn't work great with datetime?

Copying my response in discord:

true and false aren't types in pulpscript, so night = false and night = true are assigning night to the value of the variables true and false - which are both 0 (as are all unassigned variables in pulpscript).

So if night == true is equivalent to if 0 == 0 and will always pass that conditional.

Hence invert is being called on every update.

tl;dr use 0 and 1 instead of true and false.

1 Like