Can I use real clock times to load certain background images?

hi guys, so what I’m trying to do is make use of real times (os.time) so that it loads either a night or day theme.

So for example the game loads, it reads the current time, and then loads a certain image set dependant of that time frame. Can this be done? 

I currently have my game loading random images through this: 

background = { "images/BG-1.png", "images/BG-2.png", "images/BG-3.png", }

 BG = display.newImageRect(background[math.random(1,3)],482,322)

Thanks.

Dip

Yes

How can this be done? I have no idea of the best way to do it.

(os.date("*t")).hour will give you actual hour. Then you select imsge based on your decision if this hour is night or day.

Thanks for the reply, Could you give me an example of way to set it up? I am still lost trying to do it. 

cheers

[code=auto:0]
local background
local hour = (os.date("*t")).hour
if hour > 20 or hour < 8 then
– night
background = display.newImage(“night.png”)
else
background = display.newImage(“day.png”)
end
[\code]

Thanks piotrz55, that looks great. Thanks for the help.

Yes

How can this be done? I have no idea of the best way to do it.

(os.date("*t")).hour will give you actual hour. Then you select imsge based on your decision if this hour is night or day.

Thanks for the reply, Could you give me an example of way to set it up? I am still lost trying to do it. 

cheers

[code=auto:0]
local background
local hour = (os.date("*t")).hour
if hour > 20 or hour < 8 then
– night
background = display.newImage(“night.png”)
else
background = display.newImage(“day.png”)
end
[\code]

Thanks piotrz55, that looks great. Thanks for the help.