Page 1 of 1

Display of Time of Day

Posted: Thu May 16, 2013 6:02 pm
by DexterNemrod
Or to say it alternatively:
Display of, how many time of Sunlight ( or night ) remains, till the condition changes.
(could also be some kind of graphical display ... maybe a small display of a sun/moon that appears on some horizon on the left, then rises till the middle of the display and finally sinks and vanishes at the right of the display)

I don´t know how the others do it, but I usually prefer to stay/work in the well lit conditions of my base/s during the nighttime and only venture into the wilderness during the night.
Therefore, especially if I am planning long distance voyages into the wilderness, it would be extremly useful for me to know if there is enough daytime remaining (or if I rather should stay at home and do it at the beginning of the next day)

Re: Display of Time of Day

Posted: Fri May 17, 2013 3:04 pm
by ssilk
Other ways to display it:
- Shadows of the buildings/trees changes
- The light has different colors. Day: White, Morning/Evening: Red, Night: Blue

Re: Display of Time of Day

Posted: Fri May 17, 2013 8:06 pm
by metzyn
I made a quick mod that shows you the time of day. It doesn't look nice or anything as the GUI API seems a bit buggy, however it does work. I used that as a good indicator.

Re: Display of Time of Day

Posted: Fri May 17, 2013 10:23 pm
by MF-
Perhaps one could build such device in-game by observing the power output of a solar panel?

Re: Display of Time of Day

Posted: Sat May 18, 2013 1:29 am
by metzyn
MF- wrote:Perhaps one could build such device in-game by observing the power output of a solar panel?
LOL... yup, just look at the power output of a solar panel to get a good indication.

Re: Display of Time of Day

Posted: Sat May 18, 2013 2:19 pm
by DexterNemrod
Made ony myself now as well by using getdaytime() and doing an array lookup to convert it into a 24hour timescale, although it is rather rudimentary by now.
Still have to find out how the heck I can change the text color of labels from black to another (white, for example).
At the moment the label is rather difficult to read because of its black color :D

Re: Display of Time of Day

Posted: Sat May 18, 2013 11:02 pm
by kovarex
https://forums.factorio.com/wiki/inde ... Properties
https://forums.factorio.com/wiki/index.php/Lua/Font

so, you can write for example:

Code: Select all

mylabel.font={color={r=1, g=1, b=1}, bold=true}
To have bold white colored label.

Re: Display of Time of Day

Posted: Sun May 19, 2013 2:11 am
by DexterNemrod
Thanks a lot.

I already tried several approaches but was stumped, as even those approaches that didn´t give me errors didn´t change the color.
And even your approach didn´t change the color (initially).

It turned out that I made 2 errors ... the first one was (in my own approaches) to use round brackets instead of curly ones,
the second (which also affected my first trial with your approach) was, to assume that the changed mod would also affect games that had been saved (under an earlier version of the mod).
After starting a new game, I now have a nice white display of the time of day in the upper left corner :)

I think I will put it into the mod-library (after some tweaking with the numbers saved in the array ... I divided a 24 hours day into 10 equidistant chunks ... but for some reason the dark hours of the night seem to be rather short (only 0.25 of the total 1 time units) ... tweaking the array so that the distances between the hours in the night are bigger in my array will do the trick)

Re: Display of Time of Day

Posted: Sun May 19, 2013 9:17 pm
by metzyn
This is the code I use to display a digital clock at the top-left of the screen. I put this in "control.lua" file for a new mod I'm working on.

Code: Select all

require "defines"

game.oninit(function()
	game.player.gui.left.add{
		type="label",
		name="label_time",
		caption="time"
	}
end)

game.onevent(defines.events, function(event)
	if event.name == defines.events.ontick then
	
		game.player.gui.left.label_time.font = {
			color = {r=1, g=1, b=1},
			bold = true
		}
		
		-- format time
		local time = game.getdaytime()
		time = time + 0.5
		if time > 1 then
			time = time - 1
		end
		
		-- format hour
		local hour = math.floor(time * 24)
		local meridiem = "AM"
		if hour > 12 then
			hour = hour - 12
			meridiem = "PM"
		end
		
		-- format minute
		--local minute = math.floor(60 * ((time * 24) - (time * 24)))
		local minute = math.floor(60 * ((time * 24) - math.floor(time * 24)))
		if minute < 10 then
			minute = "0" .. minute
		end
		
		-- display time
		game.player.gui.left.label_time.caption =
			hour .. ":" .. minute .. " " .. meridiem
			
	end
end)