0 votes
by (950 points)


after greyelf helped me to solve my sleep and shower problem... I now need a countdown that would work in any passage. I found a couple of simple countdown macros, but I am afraid since I installed the gregorian java calendar that MadExile has posted once somewhere, it would get messy using that. Therefore I thought it would be better if directly finding a solution using the already installed clock I have. This is the installed clock I have on my game.

Idea is that the Timer starts when certain actions are performed from there on out out it suppose to count a certain amount of days ...or even weeks.. and when the time is over, it suppose to show another action. I need that timer to work on every passage and not loose track of the countdown from one passage to the next... I am not even sure if that is possible at all...

Thank you in advance...  ah, learning all of this makes me feel like such a noob (which I am at least right now XD)


Mr. Peppermint


2 Answers

+2 votes
by (159k points)
selected by
Best answer

That set of widgets uses a Date variable named $gameDate to track the current date and time (known as a time-stamp), and internally the Java-script Date object is just the number of milliseconds since a known date and time.

You can use that knowledge to compare two Date objects to see which one is later or earlier than the other.

/% e.g. 3:15am on 17th of March 2017  %/
<<set $gameDate to new Date(2017, 2, 17, 3, 15)>>

/% e.g. 3:30am on 17th of March 2017  %/
<<set $laterDate to new Date(2017, 2, 17, 3, 30)>>

/% e.g. 3:00am on 17th of March 2017  %/
<<set $earlierDate to new Date(2017, 2, 17, 3, 0)>>

gameDate: $gameDate
laterDate: $laterDate
earlierDate: $earlierDate

<<if $laterDate > $gameDate>>laterDate is later (greater) than gameDate
\<<else>>laterDate is not later (greater) than gameDate<</if>>

<<if $earlierDate < $gameDate>>earlierDate is earlier (less) than gameDate
\<<else>>earlierDate is not earlier (less) than gameDate<</if>>

... so you could use a variable to store the date/time value of the event and then use an (if:) macro to compare that value to the current value of the $gameDate variable.

Data types like the Date object require more storage space than primitive data types like an integer does due to the extra functionality these types of objects have, which is OK for the $gameDate value because you want to use that functionality to modify that variable's value. Such extra functionality isn't necessarily required for the date/time associated with an event because all we really need to know is it's value earlier than the $gameDate value which would indicate that the event needs to occur.

You can use the <Date>.getTime() function to obtain the numerical representation of a particular Date object and you could then store that primitive data type in a variable, and then compare that number against the $gameDate.getTime() value instead.

<<set $laterTimestamp to $laterDate.getTime()>>\
<<set $earlierTimestamp to $earlierDate.getTime()>>\

gameDate timestamp: <<= $gameDate.getTime()>>
laterDate timestamp: $laterTimestamp
earlierDate timestamp: $earlierTimestamp

<<if $laterTimestamp > $gameDate.getTime()>>laterTimestamp is later (greater) than gameDate
\<<else>>laterTimestamp is not later (greater) than gameDate<</if>>

<<if $earlierTimestamp < $gameDate.getTime()>>earlierTimestamp is earlier (less) than gameDate
\<<else>>earlierTimestamp is not earlier (less) than gameDate<</if>>


by (950 points)
That's a very nice idea... I can just set up a time which serves as the date the pregnancy can happen and use the later game date function to hide the hospital event in it... I was making things more complicated than needed while trying to find a solution for it. :)

I can work with that, thank you a lot :)
by (8.9k points)
Mr Peppermint doesn't know when the player character will fall pregnant, though.  How would he set the delivery date ($deliveryDate) to 9 months from the current $gameDate?
by (159k points)

I don't know what variable Mr Peppermint is actually using to track that the relevant character is pregnant so I will assume it is $pregnant and that that variable is being set within the Passage that describes the sexual act that ends with that result.

The following includes the setting of the $pregnant variable, the cloning of the current $gameDate value to create a new $birth variable, and the adding of exactly 9 months to the new $birth variable's value. 

Some text describing the sexual act and maybe the resulting outcome.

<<set $pregnant to true>>
<<set $birth to clone($gameDate)>>
<<run $birth.setMonth($birth.getMonth() + 9)>>

gameDate: $gameDate
birth: $birth

Obviously you may want to change day, hour, minute, and second parts of the new $birth variable's Date object value using the relevant setXXXX function on the Date object, or maybe you won't.

by (950 points)

Well, I would love for it to be more random and unpredictable but like that it can also work and can turn out to be (at least for the player) unpredictable to a point.

In StoryInit I put:

<<set $gameDate to new Date(2017, 1, 1, 8, 0)>>
<<set $laterDate to new Date(2017, 10, 17, 3, 30)>>
<<set $earlierDate to new Date(2017, 1, 1, 16, 0)>>

The earlierDate is set to a time near the current game date for testings, later on it's going to be somewhere more far away.

Now in the different rooms I put:

<<if $earlierDate > $gameDate>>You will go pregnant somewhere here when going to [[your bedroom|Your Bed]]
<<else>>You are Pregnant, congratulations future mommy.<</if>>


<<if $laterDate < $gameDate>>You feel a sharp pain... better go to the [[hospital|Hospital]]. Your child is about to be born<</if>>

both go in the same passages always together like that the player can wander around the house and the event would trigger and somewhere along you go pregnant and then at another point you deliver...

Of course, in the "Your Bed" passage I put this so the stats would change correctly:

<<if $earlierDate > $gameDate>>
<<set $Status to "Pregnant">>
<<else>>You are pregnant.<</if>>

at some point you go from bed to somewhere else and have a pregnant status.. tested it, it works like that...

It's not exactly what I wished for but it works... :)


Mr. Peppermint


by (950 points)
edited by

I begin to adore you, greyelf :D

This is looking more like it what I have been looking for:

<<set $pregnant to true>>
<<set $birth to clone($gameDate)>>
<<run $birth.setMonth($birth.getMonth() + 9)>>
//...it's clear to me where these three are needing to be at and what does setting pregnant to true actually do? Does it show that you are pregnant like if you were to print it it would show "true"? Edit: Nevermind, I got it. You need it later in the rules to create the pregnancy status ...lool took me longer to understand what it does LOL//

gameDate: $gameDate
birth: $birth
//but where do those two go into? The javasheet? Edit 2.0: *FACEPALM* Got it, it's an explaination... it's past 1 a.m now going to bed...//


by (8.9k points)

Mr Peppermint, you could build on Greyelf's method with the random() function to vary the birth date.

Here's how it might work:

/* This creates a new variable called $birthDate, which is the date of the birth.  It sets it to the current game date and time. */
<<set $birthDate to clone($gameDate)>>

/* Now we add 8 months to $birthDate */
<<run $birthDate.setMonth($birthDate.getMonth() + 9)>>

/* Now we add 3-5 weeks to $birthDate */
<<run $birthDate.setWeek($birthDate.getWeek() + random(3, 5)>>

/* Now we add 1-7 days to $birthDate */
<<run $birthDate.setDay($birthDate.getDay() + random(1, 7)>>

/* Now we add 1-24 hours to $birthDate */
<<run $birthDate.setHour($birthDate.getHour() + random(1, 24)>>

/* Now we add 1-60 minutes to $birthDate */
<<run $birthDate.setMinute($birthDate.getMinute() + random(1, 60)>>

/* $birthDate is now set to a random time and date around nine months from the current $gameDate */


by (159k points)

There are many ways you could randomise the birth date.

According to the following two quotes about healthy pregnancies from the Length of a Healthy Pregnancy Surprisingly Variable article on the livescience web-site.

On average, pregnancies lasted 38 weeks from the day of conception to the day the baby was born...

...the length of pregnancy ranged from about 35 to 40 weeks from the day of conception to the day of birth

The average number of weeks is 38 with a low of 35 and a high of 40, and if we convert those weeks into days we get 245 < 266 < 280 (a low of 245, an average of 266, and a high of 280).

You can use the differences between the low & average (21 days) and the high & average (14 days) to generate a range -21 < 0   < +14, which can then be combined with the SugarCube random() function like so.

/% e.g. 3:15am on 17th of March 2017  %/
<<set $gameDate to new Date(2017, 2, 17, 3, 15)>>

<<set $birth to clone($gameDate)>>
<<run $birth.setDate($birth.getDate() + 266 + random(-21, 14))>>

/% debug: test the generated value. %/
gameDate: $gameDate
birth: $birth

... as I commented in the the above example, I output the current values of the related variables for debugging/testing purposes so that you can see the results. That output can be safely deleted as it is not part of the solution.

0 votes
by (8.9k points)
Hi Mr Peppermint!

Can you describe what you're trying to do a bit more specifically?  It's not exactly clear what you want the clock to do.  I'm not sure whether you want a link that advances time by a set amount of time, or text that changes after a certain amount of game time has passed, or something else.
by (950 points)
I would need the countdown for a pregnancy...

I want it to happen random. I can create a pregnancy without all the technique but it is no fun like that.

My hope is that if you visit a certain passage enough times, at some point you end up pregnant and from the moment you went pregnant, the countdown is needing to count in the background like 9 month or so then give access to the hospital passage.

I read about the <<random>> tag which probably comes in handy, too, probably together with the <<if>> tag and then there needs to be the clock init... I just fail to get the idea of how ...



Mr. Peppermint.
by (950 points)
It's hard for me as a not native ... but I am trying my best to be as specific as possible.

I want a player to be able to get pregnant at any point of the game and if possible even more than once... so if the player chooses to have just one baby, that's fine as well as if they decided to have a sibling with the first baby... my idea was to use an sort of an "Let's have a baby" passage on it that would be the only passage in which the player is able to get pregnant. Inside that passage a timer would begin the pregnancy and change the $Status to "Pregnant" (keeping the status at that till the pregnancy ends in birth.) and run a timer on which is counted when the "birth" action is going to trigger. (That random birthing is explained quite well above in all of everyones replies)

Practically, to get an exact date the moment you visiting the passage (successfully)... like reading the current time when you visit that passage and use that time as the point of when the pregnancy has started..added with a randomness that not automatically ends in pregnancy but let's say 1 out of 10 times.

I don't want to set up a specific date for the pregnancy to begin... I would rather have it happen at a random (not knowing when it happens but knowing it can when you visit the "Let's have a baby passage). So visiting the "Let's have a baby" passage not automatically leads to a pregnancy, but it can...

Hm... not sure if now the explain is better than before... *hangs head*

Off to work, being back later to read up ;) *waves at everyone*


Mr. Peppermint