0 votes
by (150 points)
Hey guys im kinda new using twine and i am using sugarcube btw.Anyways what i wanted is to ask if it's possible how can i... for example i have a coffee shop in my game and i wanted it to open 8:30 in the morning and closing it 7:00pm. I have already a local time attached in my game and it's working all i wanted is for this shop in my game to kinda sync to my current local time.. for example if the time is 8:30am it will open and the player can go in the shop but if it's already 7:00pm it will close and the player could no longer get in and enjoy a coffee.. how to do this? any help would be really apreciated.. thanks.

1 Answer

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

Without knowing exactly how you are tracking time within your project it is difficult to offer a solution to show how to use that time to determine when something is open or closed.

Generally you would use one or more varaibles to track the current state of something, and then use an <<if>> macro to determine is a link allowing access to the coffee shop should be shown or not.

basic example: If you had two variables named $hour and $minute and if those variables were currenly equal to 8 and 30

<<set $hour to 8>>
<<set $minute to 30>>

... then you could use a condition like the following to determine if the current time is later than the start of the open period.

<<set _time to ($hours * 60) + $minutes>>

<<if _time gte 510>>[[Enter the Coffee Shop|Coffee Shop]]<</if>>

note: 8:30am is 510 minutes after midnight.

You would next extend the above condition to also determine if the current time is earlier than the end of the open period.

<<if _time gte 510 and _time lt 1140>>[[Enter the Coffee Shop|Coffee Shop]]<</if>>

note: 7:00pm is 1140 minutes after midnight.

You could further extend the about condition to show a 'closed' message when the current time is outside the open period.

<<if _time gte 510 and _time lt 1140>>[[Enter the Coffee Shop|Coffee Shop]]\
<<else>>Coffee Shop Closed<</if>>

WARNING: The above examples make assumptions about your project that may not be correct, but the general technique would work even if you are using a JavaScript Date object to track the current time within your project.

by (150 points)
Thanks a lot but i have a problem it's not working cu'z everytime it just says the shop is closed even if the the time is in the opening hours it's still telling me that the shop is closed. btw i'm using this Javascript to determine my current local time

Is there anyway you can explain it to me further? or am i missing something?

sorry for bothering you again.

BTW just wanted to show This is the javascript that determines my local time i wanted my shop to be insync whatever my current time is.

  /* Date code - Start */
window.getDayName = function(CurDate) {
    return ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"][CurDate.getDay()];
/* Date code - End */
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.