Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Time Display

Hi, so I want to implement an in game time system (I'm using Harlowe).

Basically I want certain actions (hanging out with people/exploring/etc) to take up time and there are only so many hours in a day before you rest and at certain days certain things happen. Now, I know how to make the day counter go: When you 'rest' the day counter goes up. It's also displayed when you're in the bedroom.

My problem seems to be the time. I want it to be in the header on the far right corner.

In my startup page, I have
(set: $days to 0)
(set: $turn to 0)

(if: $turn >= 8)[
	(set: $day to $day + 1)
	(set: $turn to 0)
	(print: "It's getting late so you decide to go home and get some rest.") (goto:Home)]

On a seperate page labeled time I have
(if: $turn is 1) [(set: $time to "Dawn")]
(if: $turn is 2) [(set: $time to "Early Morning")]
(if: $turn is 3) [(set: $time to "Morning")]
(if: $turn is 4) [(set: $time to "Afternoon")]
(if: $turn is 5) [(set: $time to "Evening")]
(if: $turn is 6) [(set: $time to "Evening")]
(if: $turn is 7) [(set: $time to "Sunset")]
(if: $turn is 8) [(set: $time to "Midnight")]

Before you comment, yes, I know 5&6 are evening but that's when most of the characters are supposed to be off work.

My problem is, this doesn't work.

My header is supposed to constantly display a link to inv/relationships/stats/etc and then the 'time'. I tried this as
(if: (passage:)'s name is "inventory")[<!--Do nothing-->]
(else-if: (passage:)'s tags contains "donotshowinventory")[<!--Do nothing-->]
(else:)[ [[Inventory|inventory]] [[Relationships]] [[Stats]] [[Tablet]] 	(print: $time)

]

Does anyone know what I'm doing wrong or how I can do this better?

Comments

  • edited May 2017
    (if: (passage:)'s name is "inventory")[<!--Do nothing-->]
    (else-if: (passage:)'s tags contains "donotshowinventory")[<!--Do nothing-->]
    (else:)[ [[Inventory|inventory]] [[Relationships]] [[Stats]] [[Tablet]] 	(print: $time)
    
    ]
    

    This is significantly more complicated than it needs to be. Generally, if you have hooks whose job is to do nothing, there's a better way to do it. It doesn't matter all that much, but it is wasteful and confusing to have empty conditions. Why not just:
    (unless: (passage:)'s name is 'inventory' or (passage:)'s tags contains 'donotshowinventory')[ [[Inventory|inventory]] [[Relationships]] [[Stats]] [[Tablet]] 	(print: $time)
    
    ]
    

    As to the main issue, it might be a few things:

    1. Could it be that $turn is 0? I imagine you're setting it to 1 in the 'Home' passage, but we're not seeing that here.

    2. You say that a separate passage called 'time' takes the $turn variable and sets the $time value accordingly. I imagine you're (display:)ing that passage somewhere, but where? That code needs to run for $time to be anything--maybe display it in a header-tagged passage?

    3. The code in your startup-tagged passage has a similar problem. Is it being called anywhere else? Passages sort of behave like functions--they need to be invoked for their code to run.

    4. Minor issue: why aren't you using (elseif:)s?

    My suggestion would be to try something like this:
    ::init [startup]
    {
    (set: $days to 0)
    (set: $turn to 0)
    (set: $time to '')
    }
    
    ::header [header]
    (display: 'time')\
    (unless: (passage:)'s name is 'inventory' or (passage:)'s tags contains 'donotshowinventory')[ [[Inventory|inventory]] [[Relationships]] [[Stats]] [[Tablet]] 	(print: $time)
    
    ]
    
    ::time
    {
    <!-- note the elseif statements -->
    (if: $turn is 1)[
        (set: $time to "Dawn")]
    (elseif: $turn is 2)[
        (set: $time to "Early Morning")]
    (elseif: $turn is 3)[
        (set: $time to "Morning")]
    (elseif: $turn is 4)[
        (set: $time to "Afternoon")]
    (elseif: $turn is 5 or $turn is 6)[
        (set: $time to "Evening")]
    (elseif: $turn is 7)[
        (set: $time to "Sunset")]
    (elseif: $turn >= 8)[
        (set: $time to "Midnight")
        (set: $day to $day + 1)
        (set: $turn to 0) 
        (goto: 'Home')
        <!-- this (goto:) will fire before the player has a chance to read the (print:), so just include it in the 'Home' passage; also, you don't need (print:) to write some text -->]
    }
    
    ::Home
    (set: $turn to 1)\
    It's getting late so you decide to go home and get some rest.
    
    blah blah blah, etc.
    

    This code is in Twee format; '::' denotes a passage, and the format is ::(passage name) [(tags in the brackets)].
  • @deadcheese: Please state the name and full version number of the Story Format you are using, as answers can be different for each one. It also helps us provide reference links to the correct version of a story format's documentation, I will assume you are using the current default version of Harlowe which is v1.2.4

    @deadcheese & @Chapel: Instead of using Collapsing whitespace markup to reduce any unwanted output generated by a startup tagged special passage you should use CSS like the following in your Story Stylesheet area to hide it completely.
    tw-include[type="startup"] {
    	display: none;
    }
    
    note: the above technique also works for the Harlow 2.x series.
  • Try setting up an array of $time values and then using $turn as an index to access it.

    At a guess (I'm not a Harlowe coder):
    (set: $timeOfDay to (array: "Dawn", "Early Morning", "Morning", "Afternoon", "Evening", "Evening", "Sunset", "Midnight"))
    (set: $time to $timeOfDay's ($turn))
    

    Might need a -1 in there if the arrays are zero based. You'll also need to range check $turn before you make the lookup (setting it to 1 if it's set to 9).
  • greyelf wrote: »
    @deadcheese & @Chapel: Instead of using Collapsing whitespace markup to reduce any unwanted output generated by a startup tagged special passage you should use CSS like the following in your Story Stylesheet area to hide it completely.
    tw-include[type="startup"] {
    	display: none;
    }
    

    Noted. Thanks for the tip.
  • Thank you so much for your input, peeps! My issue has been resolved!
  • Hey everyone, I'm a novice Twine user, and I'm trying to do exactly the same kind of thing as deadcheese, but using Sugarcube 2.14. I want to have the day and time in the sidebar, where the player starts on Friday at 7:30 AM, and each action takes a certain amount of time. I've dug into the code of at least one game with a similar mechanic, but there's a lot going on in this game, and I'm not sure what's relevant and what isn't. If someone could walk me through the basics here, I'd be very much appreciative!
Sign In or Register to comment.