Hi everyone, I'm having a lot of problems trying to make a time system for my game. I want a sturdy time system because I want to make a business managment simulator kind of game, so I have to keep track of the day of the week, the day of the month, the month and the year, so this are my variables.
$hour
$minute
$weekday
$monthday
$month
$year
I need the game to do the basic maths while you are playing, like not going over 59 minutes or over 23 hours. I tried setting up a conditinal.
<<if $minute > 59>>
<<set $hour += 1>>
<<set $minute -= 60>>
<<else>>
<</if>>
Its the only thing that I can think of. For days of the week, I think it would be cool to have like a string of the seven days of the week and that when $hour reaches more than 23, the hour should go down to 0 again and the day of the week and the day of the month should change.
I dont really know if this or something like this has been answered here, but i searched for a bit and didn't found anything useful.
Thank you for your time and I will be happy to listen to every piece of advice that you could give me.
Comments
note: I will use indentation and extra line-breaks in the following examples to format them so they are more readable, that formatting can be safely removed.
1. Initialise the variable in your StoryInit passage.
The Date object's documentation explains the different ways you can do this, my example is midnight on the first day of the first month of the year 2000.
2. Add Javascript code to help with the changing of the game time.
The following Javascript code creates a setup.changeDate(date, interval, units) function which you will used to change the date. The interval values it supports are 'years', 'quarters', 'months', 'weeks', 'days', 'hours', 'minutes', and 'seconds'.
warning: Always use the largest interval that meets your needs, do not try to add multiple days in a single call using a large number of 'hours', 'minutes', or 'seconds' because this can cause the date to become incorrect if you traverse over a leap-year delimiter.
Add the following to your story's Story Javascript area.
3. Example of using the setup.changeDate to change game time.
You can use the Date object's in-built methods to access the different components (year, month, date, etc...) of the $now variable, and to change the format of the outputed date String. You could use SugarCube's <<widget>> macro or it's Macro API to make custom macros to help you with the calls to the setup.changeDate function.
It just displays:
Can anybody help?
The following <<widget>> macro uses the toLocaleString function of the Javascript Date object to output a formatted String version of the $now variable. ... and you use the new <<show-now>> widget like so:
Hey! This is super helpful I only struggle with one little thing. I don't manage to only display date and most ideally I would like it to display Weekday, Day, Month, Year i.e. 'Tuesday 10th January, 2017'
I found the javascript code but I can't manage to include it in such way that Twine actually takes it. I use the latest versions of SugarCube & Twine.
If you could help me out with that, that would be awesome.
https://twinery.org/forum/discussion/3195/clocks-still-driving-me-nuts#latest
Worked 100% for me!
Trying to use the above code in SugarCube 2. Ideally I just want the hour & minutes and to alter it in game passage by passage, and spit out the time in a sidebar.
However, I'm struggling to find a way to print *just* the hour and minutes, since I don't need the whole year thing up above, and not in the D/M/Y setting since it's a fantasy game. (If anything, it would be '7th day of Whitefall' or something)
I really don't want to have to make my own variables, because it'll make the back-end messy as hell. Especially since I want to include the time in <<if>> statements for when certain jobs can be performed.
I think I need to get getDate() to work, but the correct syntax is eluding me.
EDIT: Nvm, finally figured it out. <<print $now.getDate()>>
You probably want the <Date>.getHours() and <Date.getMinutes()> methods. For example:
... Okay, fair point. I was being a fairly entitled doosh.
I guess after several hours of trying different syntax, I got frustrated, and I had blinders on to everything else but this particular issue.
Thank you once again for your help.
How would i present the time so the person playing will know the time.
So this is the variable..
(set: $time to 9+1)
I want it to say the time is 09:40
As I suggested in your other post in another thread related to this question, you will need to use type of value, some options being:
1a. A Date value (recommended), like that shown in the examples within this threat.
1b. A Decimal (float), where the number before the decimal point could represent the hours and the number after the minutes.
2. You could also use two variables ($hour, $minute) to store the relevant values.
Once you choose how you want to store the hours and minutes in your story then someone can explain how to format the output.