0 votes
by (160 points)

Hello helpers,

First of all, I'm new to programming and everything is not easy for me, so sorry if my question seems stupid but after several searches (days ;-() I have not been able to find (or understand :-)) the solution to my problem.
I wanted to insert a date system in my story and this javascript code works well

/* A method to change a date using intervals */
if (! setup.changeDate) {
	setup.changeDate = function(date, interval, units) {

		var d = new Date(date); // Don't change original date.

		switch(interval.toLowerCase()) {
			case 'years':
				d.setFullYear(d.getFullYear() + units);
			case 'quarters':
				d.setMonth(d.getMonth() + 3 * units);
			case 'months':
				d.setMonth(d.getMonth() + units);
			case 'weeks':
				d.setDate(d.getDate() + 7 * units);
			case 'days':
				d.setDate(d.getDate() + units);
			case 'hours':
				d.setTime(d.getTime() + units * 3600000);
			case 'minutes':
				d.setTime(d.getTime() + units * 60000);
			case 'seconds':
				d.setTime(d.getTime() + units * 1000);

		return d;

with these indications

Example of using the setup.changeDate to change game time.

original date: <<print $now>>

<<set $now to setup.changeDate($now, 'minutes', 15)>>
Added 15 minutes of game time: <<print $now>>

<<set $now to setup.changeDate($now, 'hours', 2)>>
Added 2 hours of game time: <<print $now>>

but I can't find a way to add 1 hour when I click on a link or image as you can easily do with a variable

example if you are in a passage named test with a variable $hour

[[add 1 hour | test] [$hour += 1]]

I don't have the right synthax to change the time. So does someone know it ? Or maybe it's not a synthax issue and in this case i'm lost. I have already test the widget time but same issue.

The second concern will be to only update the variable without refreshing the whole page but it will be for another post after readings and research i guess ;-)

1 Answer

+1 vote
by (159k points)
selected by
Best answer

I'm not sure I would call it Greyelf's Time System as such but...

You could use the <<link>> macro like so.

<<link "add 1 hour" "test">>
	<<set $now to setup.changeDate($now, 'hours', 1)>>

warning: the above was written from memory and hasn't been tested, it may contain syntax errors.

by (160 points)

It works !

Now it only remains to find how to avoid the blinking effect when you press the link several times.

(refresh the variable not the passage)

I'm not sure I would call it Greyelf's Time System as such but...

It's to make the search easier compared to a previous post. 

And thank you for taking the time to answer Greyelf (easy pun i know ;-))