Adding dynamic time suffixes to Twine links without using custom macros

I am working on a Twine game using the Sugarcube format and attempting to implement a feature that dynamically adds a time suffix to all hyperlink texts in the story, based on the time increment associated with each link (e.g., increasing the in-game time by “n” minutes with a format like ($gameTime.setMinutes($gameTime.getMinutes() + n))). Each link has a different “n” value. The time suffix should be displayed in the format (00:00). I would like to find a solution that is compatible with the standard Sugarcube link syntax (e.g., [[link|passage]] and <<link "passage">>), and avoid using custom macros. I would appreciate any guidance or suggestions on how to achieve this functionality.

Do you mean printing a different word in the link dependant on the value of the variable?
<<link 'Some Text <<if $gameTime is "morning">>extra text<<elseif $gameTime is "evening>>different extra text>>' 'PASSAGE NAME'>><</link>>
Or printing the variable in the link?
[["some text" + $gameTime + "more text if needed"|PASSAGE NAME]]

Or did you mean something else?

2 Likes

I am trying to implement a feature in a Twine game using the Sugarcube format, where I want to add a time suffix to all link texts in the form of ($gameTime.setMinutes($gameTime.getMinutes() + n)). The value of “n” varies for each link. I’d like to avoid using custom macros and find a solution that works with [ [] ] and <> syntax. I’ve seen this feature implemented in another game, but the source code is too long (over 100,000 lines) to find the relevant part. Any suggestions on how to achieve this functionality would be appreciated.

(e.g., increasing the in-game time by “n” minutes with a format like ($gameTime.setMinutes($gameTime.getMinutes() + n))). Each link has a different “n” value. The time suffix should be displayed in the format (00:00). I would like to find a solution that is compatible with the standard Sugarcube link syntax (e.g., [[link|passage]] and <<link "passage">>), and avoid using custom macros.

If you’d want something to do it automatically for each link, then you would need to use/create a custom macro.

Side note:
($gameTime.setMinutes($gameTime.getMinutes() + n))
would be something like this in SugarCube:
<<set $gameTime.minutes to $gameTime.minuted + n>>
(assuming that $gameTime is an object:
$gameTime = {hours : 0, minutes:0}

1 Like

Just to make sure I’m understanding what you want:

You’re looking for some custom JS that will, every time it sees a <<link>> markup, read the value of n and display that after the text of the link in the “(00:00)” format, without you having to explicitly invoke it with a macro? And presumably if n is greater than or equal to 60 you want it to display e.g. “(01:00)” instead of “(00:60)”?

Edit: Or, wait, you want it to automatically add the markup to set minutes + n and then display the value of n? How are you planning to tell it what the value of “n” is for each link?

What was the game you saw that did this?

1 Like

Thank you for your response. To clarify, I would like to display a link similar to this: [[Go out|Village][$gameTime.setMinutes($gameTime.getMinutes() + 5)]], and then show “Go out (00:05)” where the link text includes a time suffix based on the “n” value. I’ve seen other games achieve this functionality. Is there any way to accomplish this? I appreciate your help.

Thank you for your response. Yes, you’ve understood my requirement correctly. I’m looking for custom JavaScript that automatically reads the value of “n” and displays it after the text of the link in the “(00:00)” format, without having to explicitly invoke it with a macro. I’m also looking for a way to tell the script the value of “n” for each link.

As for the game I mentioned, it’s called “Degrees of Lewdity” (DoL). I remember it implemented this feature without using custom macros, although it’s possible that I might be mistaken.

I checked out the code of game mentioned

The game does it manually in the links
[[Robin's room (0:01)|Robin's Room Entrance]]

There is no automatic suffix added at the end of the links with JavaScript code.

1 Like

I don’t think you’re going to be able to indicate the value of n without manually adding something to each link, which if you want to avoid custom macros would probably look like <<link "Link text" "Link destination">><<set $minutes = n>><</link>>.

1 Like

Thank you for your response. According to @manonamora , they found that this feature was manually written into the links, and I misunderstood the implementation method. I appreciate your help and thank you once again for your answer.

2 Likes

Thank you for taking the time to check the game code. If the game adds the time suffix manually to the links, then I might have misunderstood the implementation. I appreciate your efforts in helping me.