0 votes
by (390 points)

So, i found a simple way to make a clock that works well enough for what i'm trying to accomplish.

It's set like so:

<<set $hour to State.turns % 144>>
\<<if $hour <= 1>>00:00<</if>>
\<<if $hour > 2 and $hour <= 3>>00:10<</if>>
\<<if $hour > 3 and $hour <= 4>>00:20<</if>>
\<<if $hour > 4 and $hour <= 5>>00:30<</if>>
\<<if $hour > 5 and $hour <= 6>>00:40<</if>>
\<<if $hour > 6 and $hour <= 7>>00:50<</if>>
\<<if $hour > 7 and $hour <= 8>>01:00<</if>>
\<<if $hour > 8 and $hour <= 9>>01:10<</if>>
\<<if $hour > 9 and $hour <= 10>>01:20<</if>>
\<<if $hour > 10 and $hour <= 11>>01:30<</if>>
\<<if $hour > 11 and $hour <= 12>>01:40<</if>>
\<<if $hour > 12 and $hour <= 13>>01:50<</if>>
\<<if $hour > 13 and $hour <= 14>>02:00<</if>>
\<<if $hour > 14 and $hour <= 15>>02:10<</if>>
\<<if $hour > 15 and $hour <= 16>>02:20<</if>>
\<<if $hour > 16 and $hour <= 17>>02:30<</if>>
\<<if $hour > 17 and $hour <= 18>>02:40<</if>>
\<<if $hour > 18 and $hour <= 19>>02:50<</if>>
\<<if $hour > 19 and $hour <= 20>>03:00<</if>>
\<<if $hour > 20 and $hour <= 21>>03:10<</if>>
\<<if $hour > 21 and $hour <= 22>>03:20<</if>>
\<<if $hour > 22 and $hour <= 23>>03:30<</if>>
\<<if $hour > 23 and $hour <= 24>>03:40<</if>>
\<<if $hour > 24 and $hour <= 25>>03:50<</if>>
\<<if $hour > 25 and $hour <= 26>>04:00<</if>>
\<<if $hour > 26 and $hour <= 27>>04:10<</if>>
\<<if $hour > 27 and $hour <= 28>>04:20<</if>>
\<<if $hour > 28 and $hour <= 29>>04:30<</if>>
\<<if $hour > 29 and $hour <= 30>>04:40<</if>>
\<<if $hour > 30 and $hour <= 31>>04:50<</if>>
\<<if $hour > 31 and $hour <= 32>>05:00<</if>>
\<<if $hour > 32 and $hour <= 33>>05:10<</if>>
\<<if $hour > 33 and $hour <= 34>>05:20<</if>>
\<<if $hour > 34 and $hour <= 35>>05:30<</if>>
\<<if $hour > 35 and $hour <= 36>>05:40<</if>>
\<<if $hour > 36 and $hour <= 37>>05:50<</if>>
\<<if $hour > 37 and $hour <= 38>>06:00<</if>>
\<<if $hour > 38 and $hour <= 39>>06:10<</if>>
\<<if $hour > 39 and $hour <= 40>>06:20<</if>>
\<<if $hour > 40 and $hour <= 41>>06:30<</if>>
\<<if $hour > 41 and $hour <= 42>>06:40<</if>>
\<<if $hour > 42 and $hour <= 43>>06:50<</if>>
\<<if $hour > 43 and $hour <= 44>>07:00<</if>>
\<<if $hour > 44 and $hour <= 45>>07:10<</if>>
\<<if $hour > 45 and $hour <= 46>>07:20<</if>>
\<<if $hour > 46 and $hour <= 47>>07:30<</if>>
\<<if $hour > 47 and $hour <= 48>>07:40<</if>>
\<<if $hour > 48 and $hour <= 49>>07:50<</if>>
\<<if $hour > 49 and $hour <= 50>>08:00<</if>>
\<<if $hour > 50 and $hour <= 51>>08:10<</if>>
\<<if $hour > 51 and $hour <= 52>>08:20<</if>>
\<<if $hour > 52 and $hour <= 53>>08:30<</if>>
\<<if $hour > 53 and $hour <= 54>>08:40<</if>>
\<<if $hour > 54 and $hour <= 55>>08:50<</if>>
\<<if $hour > 55 and $hour <= 56>>09:00<</if>>
\<<if $hour > 56 and $hour <= 57>>09:10<</if>>
\<<if $hour > 57 and $hour <= 58>>09:20<</if>>
\<<if $hour > 58 and $hour <= 59>>09:30<</if>>
\<<if $hour > 59 and $hour <= 60>>09:40<</if>>
\<<if $hour > 60 and $hour <= 61>>09:50<</if>>
\<<if $hour > 61 and $hour <= 62>>10:00<</if>>
\<<if $hour > 62 and $hour <= 63>>10:10<</if>>
\<<if $hour > 63 and $hour <= 64>>10:20<</if>>
\<<if $hour > 64 and $hour <= 65>>10:30<</if>>
\<<if $hour > 65 and $hour <= 66>>10:40<</if>>
\<<if $hour > 66 and $hour <= 67>>10:50<</if>>
\<<if $hour > 67 and $hour <= 68>>11:00<</if>>
\<<if $hour > 68 and $hour <= 69>>11:10<</if>>
\<<if $hour > 69 and $hour <= 70>>11:20<</if>>
\<<if $hour > 70 and $hour <= 71>>11:30<</if>>
\<<if $hour > 71 and $hour <= 72>>11:40<</if>>
\<<if $hour > 72 and $hour <= 73>>11:50<</if>>
\<<if $hour > 73 and $hour <= 74>>12:00<</if>>
\<<if $hour > 74 and $hour <= 75>>12:10<</if>>
\<<if $hour > 75 and $hour <= 76>>12:20<</if>>
\<<if $hour > 76 and $hour <= 77>>12:30<</if>>
\<<if $hour > 77 and $hour <= 78>>12:40<</if>>
\<<if $hour > 78 and $hour <= 79>>12:50<</if>>
\<<if $hour > 79 and $hour <= 80>>13:00<</if>>
\<<if $hour > 80 and $hour <= 81>>13:10<</if>>
...and so on...
\<<if $hour > 143 and $hour <= 144>>23:40<</if>>
\<<if $hour > 144>>23:50<</if>>

What this does is that for every passage i go through it counts ten minutes, that's why it has 144 turns, it's because there's 144 sets of ten minutes in 24 hours.

But my problem is, for every passage i go through it ONLY adds 10 minutes, i tried making a passage that adds 3 hours, and it doesn't add anything. One of the macros i set to add time:

<<set state.turns += 45>>

But this macro only shows a message saying: "" Error: <<set>>: bad evaluation: Cannot set property turns of #<Object> which has only a getter ""

I tried a bunch of ways to add time, none of them seem to work.

Can anyone help?

2 Answers

+1 vote
by (63.1k points)
edited by

Don't store this data on the read-only turns property. If you need to alter it, just make your own variable and count that.

Here's a replacement for that mess of <<if>>s as well: 

<<set _time to $turns % 144>>
<<set _hour to (_time - 1) / 6>>
<<set _min to (_time - 1) % 6>>
<<if _hour lt 10>>
    <<set _hour to "0" + _hour>>
<</if>>

<<= _hour + ":" + _min + "0">>

You can get rid of the - 1 parts of you start at 0 instead of one. 

You could also just use the date object, which would be even easier. 

by (8.6k points)
Using the modulo operator he automatically starts at 0. For positive numbers, it returns values between 0 (inclusive) and the second argument (exclusive), so in this case 0 to 143 (if we're using integers) or 0 to 143.99999999999997 (if we're using floating-point numbers; the second value corresponds to the IEEE754 double precision value of 0x4061FFFFFFFFFFFF).
by (390 points)

Well, i'm still trying to learn more stuff about Twine 2, specially sugarcube, it's such a complete program, you can do so much on it! That's why i'm dragging myself to make mistakes and learn as much as i can with it, i can really see myself doing my dream game here, i just need time and practice, i've only started two weeks ago! laugh

 

By the way, great job on those custom macros you did, i implemented the cycles one on one of my experiments, but i can't seem to set <<if>>'s to recognise certain parts of the cycle.

 

Like for instance, i have it set up like this:

<<newcycle 'time' 'morning' 'afternoon' 'evening' 'night' 144>>

And i wanted to make a passage that only appears between afternoon and evening, i set it up like so:

\<<if $cycles['time'].time gte 'afternoon' and $cycles['time'].time lte 'evening'>>
You can [[work here]].
\<</if>>

It doesn't show any error message, it just doesn't appear. What am i doing wrong? Do i have to set some kind of variable, or define it perhaps?

 

Oh, and thank you for replying! smiley

+1 vote
by (44.7k points)

You are making so much extra work for yourself by ignoring all of the examples you were given in your previous question.

For a time system you can store a date like this (preferably in StoryInit):

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

Then you should add something like this to your JavaScript section:

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

window.showTime = function() {
    return State.variables.CurDate.toLocaleString('en-US', { hour: 'numeric', minute: 'numeric', hour12: true });
};

Now you can just do something like this whenever you want to add 10 minutes to the current game time:

<<set addMinutes(10)>>

To display the time just do:

<<print showTime()>>

For further ways to manipulate dates see the JavaScript date functions.

by (390 points)

Thank you once again for replying.

Believe me, i did not ignore the links you provided me with, i read each one more than once, but there are still many things i don't even begin to understand in twine.

The language most advanced users like you use, though basic to you, go right over my head.

So most explanations leave me with more questions than answers, and that's no one's fault but mine.

That's why the code i posted here, my simple "clock" is so badly made.

Currently i'm rewatching a Sugarcube tutorial on yt, the whole 11 videos, and trying to understand the sugarcube documentation.

Like i said before, this is all very new to me, and i never did any kind of coding before.

As with everything, i'll get there eventually.

And thank you again! wink

...