Time flow macro.

Discuss macro implementations, ask for macro help (to share your creations, see User Creations, probably either Campaign Frameworks or Drop-in Resources).

Moderators: dorpond, trevor, Azhrei, giliath, jay, Mr.Ice

Post Reply
Adurna
Cave Troll
Posts: 34
Joined: Thu Jul 07, 2016 7:45 am

Time flow macro.

Post by Adurna »

Hi, I was thinking about whipping up a macro to track the passing of time.

The idea was pretty straightforward: a library token with day, month, year, hour and minute and a macro that would then add some time according to the actions the players are doing.

However, I soon realized I'd have a bit of a problem. If, say, it's 12:40 in game time and I add 30 minutes, how can I tell the macro to turn the hour to 13 and the minutes to 10 and not end up with 12:70?

I'm thinking something like:
-adding the time
-checking if any of the values are bigger than it should and if yes remove the full value. (If minutes ends up at 78, it removes 60)
But I'm not sure how to code it so that after it does so it also adds +1 to the hour value...

Do you guys have any idea how I could do this?

User avatar
wolph42
Winter Wolph
Posts: 9999
Joined: Fri Mar 20, 2009 5:40 am
Location: Netherlands
Contact:

Re: Time flow macro.

Post by wolph42 »

first off, somebody already did this. Search the forum, but there should be something like a time tracker available.

To answer your question... i would say its simple math. What you do is store daytime in minutes (e.g. on a lib:token) and convert it to a 'representative' that you show in e.g. a form.
So lets say 13:40 would be stored as:
::PSEUDO CODE::

Code: Select all

currentTime = (13*60 + 40 =) 820
if you add 30 minutes:

Code: Select all

input(newTime)
currentTime = currentTime +newTime
if currentTime > 1140 then 
currentTime = currentTime - 1140
currentDay = currentDay + 1
end if
'run macro updateShowTime'
and updateteShowTime:

Code: Select all

minutes = mod(currentTime;60)
hours = (currentTime - minutes)/60
showTime = hours + ":" + minutes
when you update time you add the hours or minutes to the currentTime and then run a macro that 'recalcs and redraws' the showTime on the form (or whatever you're using)

bobifle
Giant
Posts: 219
Joined: Thu Oct 19, 2017 12:36 pm

Re: Time flow macro.

Post by bobifle »

Always do the math with minutes.

Have your internal date counter stored as minute only. Compute years/days/hours only when displaying.

For the sake of simplicity let's consider an hour/minute calendar only:

This is pseudo code, not Maptool macro code

Code: Select all

minutes = 0
// add 1 hour, 5 minutes
minutes += 1*60 + 5

print minutes/60," hour(s), ", minutes mod 60, " minute(s)\n"

>> 1 hour(s), 5 minutes

this way, adding or subtracting time is only about doing a simple + or minus operation on the total of minutes.

Make sure your month and years have always the same number of days/minutes, otherwise the nightmare begins...

Adurna
Cave Troll
Posts: 34
Joined: Thu Jul 07, 2016 7:45 am

Re: Time flow macro.

Post by Adurna »

first off, somebody already did this. Search the forum, but there should be something like a time tracker available.
I tried a quick search, but I suck at searching. Especially since half the time it tells me that my search is too broad. I managed to find a timer macro, but that's not exactly what I had in mind.
What you do is store daytime in minutes
Yes, this sounds much simpler and sensible than what I had in mind.

IS there a limit on how much I can get the macro to compute without being too straning? That is, can I have the whole date without problems (especially on my aging pc), or would it be better to do the years manually?
With the calendar I came up with we'd start roughly at the 2.030.616.000th minute.
Make sure your month and years have always the same number of days/minutes, otherwise the nightmare begins...
Ahahah yes, I came up with a nice lunar calendar. Which is almost perfect for what I wanted.
Last edited by Adurna on Mon Oct 30, 2017 9:51 am, edited 1 time in total.

User avatar
aliasmask
RPTools Team
Posts: 9029
Joined: Tue Nov 10, 2009 6:11 pm
Location: Bay Area

Re: Time flow macro.

Post by aliasmask »


Adurna
Cave Troll
Posts: 34
Joined: Thu Jul 07, 2016 7:45 am

Re: Time flow macro.

Post by Adurna »

I made it!

Thanks, the suggestion to calculate everything in minutes saved me hours of time I think.
Now I just need to see if I have time to tweak it to display the names of the months/weekdays. But even if I don't it works well enough as it is.

I'm gonna paste it here in case someone stumbles upon it and might need something similar.
Spoiler

Code: Select all

[h: CurrentTime = getLibProperty("Time", "lib:Time")]



[h: Year = (CurrentTime / 504000)]

[h: YearP = floor(CurrentTime / 504000)]

[h: Month = CurrentTime - (YearP*504000)]
[h: MonthP = floor(Month / 50400)]

[h: Day = CurrentTime - (YearP*504000) - (MonthP*50400)]
[h: DayP = floor(Day/1680)]

[h: Hour = CurrentTime - (YearP*504000) - (MonthP*50400) - (DayP*1680)]
[h: HourP = floor(Hour/60)]

[h: MinuteP = CurrentTime - (YearP*504000) - (MonthP*50400) - (DayP*1680) - (HourP*60)]

The Date is [DayP]_[MonthP]_[YearP]  The time is [HourP]:[MinuteP]

Code: Select all

[h: Time = getLibProperty("Time", "lib:Time")]

[h: AddTime=Minute]
[h: AddMinute = Time+AddTime]


[h: setLibProperty("Time", AddMinute, "lib:Time")]
The first one displays the time, while the second adds minutes to the current time.

The numbers you see: 60, 1680, 50400, 504000 are minutes in an hour, day, month and year in the calendar I created.
I'm sure you guys could have written it better (I've been told my macros tend to have lots of stuff that is redundant or could be written shorter), but this works for me :P

Ps: the mod function you suggested in your examples apparently doesn't work in maptool :|

User avatar
wolph42
Winter Wolph
Posts: 9999
Joined: Fri Mar 20, 2009 5:40 am
Location: Netherlands
Contact:

Re: Time flow macro.

Post by wolph42 »

IS there a limit on how much I can get the macro to compute without being too straning?
yes. but not sure where that limit lies. Personally i would split it into minutes and days. But you can also split in minutes and years. You don't have to do anything manually, you just need to do some extra scripting. The mod function is ideal for those operations.

and yes, what AM linked is what I meant.

User avatar
JamzTheMan
Great Wyrm
Posts: 1872
Joined: Mon May 10, 2010 12:59 pm
Location: Chicagoland
Contact:

Re: Time flow macro.

Post by JamzTheMan »

I pretty much did the same thing for my framework, I refer to it as my "unix datetime" function. :)

FYI: I use number of seconds since 4715 (arbitrary year, based on pathfinder calendar which is current real year + 2700) with current game year 4716 or so. MapTool uses BigInteger so plenty of room to store that number. :) I use "seconds" so I can track down to the combat round (could have used rounds ie 6 seconds but meh).

Anyhoo, that was the basis for my "timer" logic. So now any spell, mod, buff, poison effect, etc can be added with a start timestamp and a end timestamp, and I can now track them all per initiative, end of round, or via calendar time advancements.

But ya, that's the best way to track time and just format the date/time as needed.
-Jamz
____________________
Custom MapTool 1.4.x.x Fork: maptool.nerps.net
Custom TokenTool 2.0 Fork: tokentool.nerps.net
More information here: MapTool Nerps! Fork

Post Reply

Return to “Macros”