0 votes
by (220 points)
I know the macro exists in Harlowe -- does it exist in Sugarcube 2? I just want the story to display whatever the user's date or time is.

 

Thanks!

1 Answer

0 votes
by (158k points)
selected by
 
Best answer

NOTE: Your question doesn't state how you want the Date and/or Time formatted, nor does it state if you want that formatting to respect the Reader's country's (locale) default Date / Time formats or if you want everyone to see the same formats.

SugarCube doesn't have built-in Date / Time displaying macros, but it would be fairly easy to add your own custom macros/widgets to do that.

Basically you would create an instance of a Javascript Date object and store that within a (temporary) variable, then use the Date object's methods and some Javascript code to format either the Date or Time portions, which you would then output to the page. Which methods you use depends on how you want the different parts formated, and if you want to respect the Reader's locale settings.

EDIT:

If you want custom macros that work exactly like Harlowe 2's (current-date:) and (current-time:) macros then do the following:

1. Create a new Passage with whatever name you like (I used StoryWidgets) and assign that Passage a tag of widget

2. Add the follow markup to the above Passage, it creates the custom <<currentdate>> and <<currenttime>> macros.

<<widget "currentdate">>\
	<<print new Date().toDateString()>>\
<</widget>>

<<widget "currenttime">>\
	<<set
		_d to new Date(),
		_am to (_d.getHours() < 12),
		_hr to ((_d.getHours() % 12) || 12),
		_mins to (_d.getMinutes() < 10 ? "0" : "") + _d.getMinutes()>>\
		<<print _hr + ":" + _mins + " " + (_am ? "A" : "P") + "M">>\
<</widget>>

3. Add markup like the following to one of your passages to use the new customer macros.

Date: <<currentdate>>
Time: <<currenttime>>

 

Welcome to Twine Q&A, where you can ask questions and receive answers from other members of the community.

You can also find hints and information on Twine on the official wiki and the old forums archive.

See a spam question? Flag it instead of downvoting. A question flagged enough times will automatically be hidden while moderators review it.
...