Checking for future variable/date

Twine Version: 2.36
Hello sorry if this question is easy, I’m very new to twine.

I’m trying to implement a date/time system using a simple $day variable with also either ‘Chapel’s Cycles System’ or the system described here (depending on which one I can get working): h t t p s://

The problem I’m having is that I can’t figure out how to check for a “future” date/variable. For example, the player does a task on Day 5, the next task in that quest will only be available in 10 days exactly.

Example (doesn’t work):

<<if $day + 10>><div class="choice"><img src="image.jpg">[[NextPsg|Psg2]]</div><</if>>\

I also tried using gte, so like if $day gte 15… can go to next passage, etc. But I found it a bit weird because what if the player does the task on Day 16… then he can already go to the next stage.

I’d really like it to work with the system explained in that link, with specific dates. Like $day = 5, specific date is December 17, so the next task can be done after December 27.

Sorry for poor explanation, but I would appreciate any help, thank you.

You’d need to save the day when the player did the task: <<set $didTaskA = $day>> and then check whether you’ve done the task and it’s exactly ten days later: <<if (def $didTaskA) and ($day is $didTaskA + 10)>>

Or it might be easier to save when the next stage is available: <<set $canDoTaskB = $date + 10>> and then you can probably skip the “is defined” part of the test: <<if $day is $canDoTaskB>>

Side note: <<if $day + 10>> is only implicitly a condition: you’re not comparing it against anything. It will do something (it roughly says “if day plus ten is not zero”) but it’s usually not what you want…

1 Like

Thank you very much, seems to be working well.

This is a little different from my original question, but if anyone could answer that would be great. I use images as links, and I’d like to also advance time using them.

How would I set this variable…

<<set $day += 1>>

…in this code?

<a data-passage="Next Passage" class="link-internal link-image">\
	<img src="images/image.png" width="10%">\

Thank you!

The documentation has the answer you seek (see: data-setter). For example, add the attribute to your <a> tag:

<a data-passage="Next Passage" data-setter="$day += 1" class="link-internal link-image">
	<img src="images/image.png" width="10%">\

NOTE: While it’s not an issue here, be mindful of quote nesting if the code you use within the setter contains strings, since the attribute’s value is itself a quoted string.