OK, I have questions about setting a clock. (This is going to be a long post, bare with me.)
So, I have successfully set up a working clock that displays in my status window. (Yay) It displays in 24 hour time. and it looks like --> "Time: 10:30"
Now there are 2 (maybe 3) things I want to do with this. But first I want to mention, I have looked up the tutorials/guides posted for references:
http://docs.textadventures.co.uk/quest/time.html
https://textadventures.co.uk/forum/samples/topic/uitsc9eqskio8b_axf-ayw/simple-weather-day-night-cycle-codes-v1-5OK so I have my attribute set up like this:
player.mins --> To show minutes.
player.hour --> To show the hour.
player.clock --> To show the time in a digital format (player.hour + ":" + player.mins)
runtime --> my turnscript for setting the time. it looks like this:
player.mins = player.mins + 10
if (player.mins = 60) {
player.hour = player.hour + 1
player.mins = 00
}
if (player.hour = 25) {
player.hour = 1
}
player.clock = player.hour + ":" + player.mins + " mins."
I used a turnscript because I want time to move when the player makes a move.
So, reading the refs, I'm a little confused to which step I need to take, where and why.
I assume it goes something like this because of how I set it up.:
In Player Object, Attribute, Add
ampm --> name for the am/pm attribute
Type: Interger, make it 0.
In Player Object, Attribute, Click on ampm, Click Add Changescript.
changedampm Script
Put in the script:
if (game.ndcycle>1) {
game.ndcycle=0
}
I understand the changedampm script is to make the am change into pm and loop it back to am, but after this I'm lost on how to set the variables to be labels as "am" and "pm" and where to set it.
I assume I add it to the runtime turnscript I created. but I don't quite know how to set it up.
I'm thinking of making another turnscript or ..? I have no idea.
Some guidance, please? and or any other corrections to the way I'm thinking of setting it up.
You might want to have a look at this library. All the work has been done for you, all you need to do is set the time/date . It even allows for events to be triggered at specific times.
https://github.com/ThePix/quest/wiki/Library:-Tracking-time
if (player.hour>12){
player.clock=(player.hour-12)+":"+player.min+" pm"
}
elif (player.hour<12){
player.clock=player.hour+":"+player.min+" am"
}
with a special case for Midnight, if you want. I think you have an off-by-one error in your Hour-reset, but I'm not sure.
As for days, that's easy peasy. Make player.daynum as an integer, and set it to 1. Also create player.daystring as a string, set it to "Monday".
Under your hour script, whenever you change player.hour back down, also do player.daynum=player.daynum+1.
Then you also have a changescript for player.daynum, like so. Pardon my psuedocode:
switch (player.daynum){
case(1){
player.daystring="Monday"
}
case(2){
player.daystring="Tuesday"
}
etc
And then you just display it wherever. Make sure to have a reset for that, too, lest you get to the 8th day of the week!
Displaying 12 hour time as opposed to 24 hour time, I covered under am/pm.
As a side, from what I'm observing, your code will encounter a problem when player.min is less than 10 If min= 5, you get something like:
9:5 pm
So you also want an if-then like so:
if (player.min>=10){
player.clock=player.hour+":"+player.min
}
else{
player.clock=player.hour+":0"+player.min
}
Hope this helps!
if (game.hour = 12) {
game.hour2 = 12
//p.m.
}
if (game.hour = 13) {
game.hour2 = 1
//p.m.
}
And so on.
I'm not sure why you would need to use changescripts here. Why not just make your turnscript:
player.mins = player.mins + 10
displaymins = "00"
if (player.mins = 60) {
player.hour = player.hour + 1
player.mins = 00
}
else {
displaymins = player.mins
}
if (player.hour = 25) {
player.hour = 1
}
if (player.hour > 12) {
player.clock = (player.hour - 12) + ":" + displaymins + " PM"
}
else {
player.clock = player.hour + ":" + displaymins + " AM"
}
(used the 'displaymins' variable so that the time shows "5:00" rather than "5:0" when player.mins is 0)
Thank you guys for laying it out for me! It's easier to understand visually.
You guys also answered some of my future questions. So this is very helpful.
I will try these out later tonight.