I am trying to learn Godot by building a medieval game. So I first built a function to change dates every second and it works ok. Than I added rulers and also check them every day(second) to see if the date when they started ruling is the current day, but it doesnt sound as efficient way to do it although it also works nicely.
So I thought would it be better to build a list of dates when the ruler change and maybe build a signal to fire when it happens. What do you think is it better and does it matter?
What's more efficient and does it matter
I'd say that at this point it doesn't really matter... Just get the thing fleshed out a bit more. I think you may find that you are actually wanting to do things with the rulers / npc on every step, even at some point you'll have so much to do that you'll be staggering the processing, yes those things may be farmed out but it sounds like the brain is in the ruler and it will have to regularly make decisions based on what is happening realtime, at least checking.
My first thought was to suggest thinking about an animation timeline, however you probably want to use a FSM (Finite State Machine) for each ruler...
Well, I suppose I wasnt clear enough. In middle ages it wasnt unusual to express that something happened in 10th year of Henry III instead of saying it happened in 1226( he started his rule in 1216) . Rulers wont be checked every step as the game wont cover directly anything about rulers except his year of rule.
Ah, ok
I wouldn't suggest adding timers for each event... Therefore how are you going to do it?
Whether you have the dates in each ruler (class) or in a single dataset (array / dictionary), it's basically the same, with the single dataset being slightly more efficient due to fewer jumps of the stack.
- Edited
ZedMcJack make a variable that clocks the time a ruler starts and then another variable that calculates the current time then calculate the distance between the start time and time elapsed. Then you subtract them, do whatever math makes your "year" and you have it.
Something like:
var _rulerStartTime = 0
var _rulerCurrentTime = 0
var _rulerYear = 0
func _start_time(): ## don't try taking system time before _ready!!
_rulerStartTime = OS.get_system_time_secs()
func _timeCheck(): ## take the current time and calculate, rounding up for your year
_rulerCurrentTime = OS.get_system_time_secs()
var _difference = (_rulerCurrentTime-_rulerStartTime)
_rulerYear = int(round(_difference)