0 votes
by (220 points)
Hello there

 

I'm trying to put a period based time system(morning-->noon-->afternoon ect,) into my game, which also automatically advances the weekday&date(and if applicable month/year) after all of the periods are cycled through once.

I've found good examples in this forum of systems for both seperately, but I'm afraid I'm still way too stupid when it comes to programming to combine them without murdering everything.

What would be the easiest to use method for me of implementing something like the above?

1 Answer

0 votes
by (44.7k points)
edited by

If you want the simplest way, just use JavaScript in your Twine code.  For example:

<<script>>State.variables.CurDate = new Date('August 19, 1975 23:15:30');<</script>>
$CurDate
<<script>>State.variables.CurDate = new Date(State.variables.CurDate.getTime() + 15*60000);<</script>>
$CurDate

In the above case it sets $CurDate to "August 19, 1975 23:15:30", displays the date and time as " 8/19/1975, 11:15:30 PM", then adds 15 minutes (60,000 milliseconds = 1 minute), and then it should display "8/19/1975, 11:30:30 PM".

You could make that a JavaScript function if you wanted to make that easier.  Just add this to your JavaScript section:

window.addMinutes = function(Min) {
    State.variables.CurDate = new Date(State.variables.CurDate.getTime() + Min*60000);
    return State.variables.CurDate;
};

Then in your Twine code you'd just do something like "<<set addMinutes(15)>>" or "<<print addMinutes(15)>>, and that would increment the time by 15 minutes, and in the latter case it would also display that new time.

So, just set your start date like above initially somewhere, and then add however much time you want.  You can use the various JavaScript Date functions if you'd like to manipulate or set the date and/or time in other ways.

Hope that helps! :-)

by (159k points)

...just use JavaScript in your Twine code.  For example:

<<script>>State.variables.CurDate = new Date('August 19, 1975 23:15:30');<</script>>
$CurDate
<<script>>State.variables.CurDate = new Date(State.variables.CurDate.getTime() + 15*60000);<</script>>
$CurDate

 

You don't need to use the <<script>> macro to assign a JavaScript data-type like Date to a story variable, the <<set>> macro can handle that.

<<set $CurDate to new Date('August 19, 1975 23:15:30')>>\
first: $CurDate

<<set $CurDate to new Date($CurDate.getTime() + 15*60000)>>\
second: $CurDate

 

by (220 points)

Thanks for answering, but it's not really what I was talking about.

I don't want a time system based on hours and minutes, because it would be needlessly complicated for what I'm trying to do.

Instead, I'm trying to find a way to combine a repeating system of time periods(morning-->noon-->afternoon-->evening--->night--->morning...ect.) with an actual advancing weekday/month/year.

Right now I use something like this in StoryInit to setup days/periods,

<<set setup.DAYS to ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"]>>

<<set setup.PERIODS to ["Morning", "Afternoon", "Evening", "Night"]>>

and I'm trying to figure out how to add a working date/month/year system to it, and how to wrap all of that up into a widget, which would simply let me advance a certain number of periods and takes care of the rest automatically.

Again, apologies if it's a dumb question.

...