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
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:
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:
This code is in Twee format; '::' denotes a passage, and the format is ::(passage name) [(tags in the brackets)].
@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. note: the above technique also works for the Harlow 2.x series.
At a guess (I'm not a Harlowe coder):
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).
Noted. Thanks for the tip.