HTML How to do time & day system/corruption meter/money in Twine/SugarCube

Atomic Brain

New Member
Mar 8, 2020
8
1
I've been looking up some tutorials online for how to write a Twine game, but so far all I've seen are very basic instructions on how to link to other pages and include pictures and stuff. I know this is probably really basic information for anyone with programming knowledge, but I have almost none. I'm trying to make a game similar to Life Choices (mainly for my own amusement, but maybe I could share it online in the future) , but I don't know how to a) program a time and day system, b) make a visual corruption and health meter or counter, and c) create a wallet or way to earn and spend money.

I know this is probably a lot of basic questions, so if anyone can just point me to some reliable tutorials in the forums or elsewhere online, it would be greatly appreciated. Thanks.
 
Mar 18, 2020
38
100
I'm still pretty new at Twine myself, and I'm constantly learning better ways of doing things. As far as a super simple way of doing things, you can set a variable to anything with a $ sign at the start. For example, my money count is stored in "$cash". Then every time you make/spend money you can add or subtract from it. Simplest place to do this on the page links. So a link would read -

[[Buy a hat][$cash -=15]]
[[Sell a hat][$cash +=15]]

In the hypothetical hat trading game I just created, this would send you to the "Buy a hat" or "Sell a hat" passage and add or subtract 15 from the total. You can also put these in if statements or anywhere else you want. The link that xcrash posted has a lot more detail and variations on how to change variables.

Once you've got the hang of it you can use the for whatever you want, $health, $corruption, etc. If you really need a visual representation you could make images for each state then set up an if statement for the bar -

<<if $health is 3>>fullhealth.jpg<<elseif $health is 2>>halfhealth.jpg<<elseif $health is 1>>lowhealth.jpg<<endif>>

There's other ways to do it too, my recommendation is play around with it and figure out the best options for your game.

Also, the above assumes you're using sugarcube. If you're using something else the coding my be slight different, but the concepts are the same.
 

BoredPenguin

New Member
Aug 21, 2020
12
9
If you want to set up a health/corruption/money counter on the left panel, you can create a passage called StoryCaption. In it you could set up a basic display as:

Health = <<print $health>>
<hr>
Corruption = <<print $corruption>>
<hr>
Money = <<print $money>>
<hr>

This will create a basic text display for those values that appears in the left panel. The <hr> just prints a line that will separate them visually and isn't necessary if you'd rather them just be separated by empty space or not at all. For a more visual representation you could put the display option SalaciousMandate posted there instead.

Day and time systems are a little more complicated depending on what you want to do. For a full clock and calendar system has a setup that you could copy/paste into a widget.

I set up a much more simple system based off of other stuff I found while googling around that just keeps track of days of the week and four time periods (morning, afternoon, evening, night) that I'd be happy to share if that suites what you're looking for better.
 
  • Like
Reactions: Atomic Brain

Hunter MC

Member
Aug 29, 2020
154
76
You could use have a $day /$hour / $minutes variable and assign a timevalue to each ingame action.
So a link could look like this

[[Go to the mountain|mountain][$minutes+=30]]

That link would send you to the mountain passage and add 30 minutes to the counter.
Then you have a PassageReady passage and in there you have something like this:

<if $minutes gt 60>><<set $hour++>><<set $minutes-=60>><</if>>
<<if $hour gt 24>><<set $hour to 0>><<set $day++>><</if>>

This will check every time a new passage is loaded and increase the hours by one and reset the minutes to the value that was over the 60.
Works fine as long as you don't want to have a real time element, since it only passes time with player actions.
 

Atomic Brain

New Member
Mar 8, 2020
8
1
I set up a much more simple system based off of other stuff I found while googling around that just keeps track of days of the week and four time periods (morning, afternoon, evening, night) that I'd be happy to share if that suites what you're looking for better.
Sorry its been a while since I first asked this, but could you still share this four period time system you have? I want to play around with which system I like better.
 

HiEv

Member
Sep 1, 2017
384
785
Sorry its been a while since I first asked this, but could you still share this four period time system you have? I want to play around with which system I like better.
It sounds like they might be referring to the last part of the "Time" section (under "Data Handling") in my .

Take a look at that and let me know if you have any questions. :)
 
  • Like
Reactions: Atomic Brain