Link that shows something + counter

Twine Version: 2.6.2
Harlowe 3.3.5

Hello my dear, fellow authors. I’ve been hitting an issue.

I want to use something like a String but i dont want it to lead on another page but show something on the page the player is right now.

For example there is a button the player needs to push multiple times:

I want it like:

push(clickable)
You have pushed the button 1 time. Nothing happens right now.

I hope you understand what i want because i dont know how to explain it further. :slight_smile:

Thanks in Advance and have a great day.

I believe what you want is the sequence link macro.

#macro_seq-link

It’s kind of like a reveal link.

#macro_link-reveal

Let us know if that works for you.

Close. I want to do it multiple times and change the text wich appears below.


Push (clickable)
You have pushed the button one time. Nothing seems to happen yet.

But when you click it again then an other text appears.

Push (clickable)
As you push the button a second time, you notice a mechanic sound behind the wall.

But i want it to happen on the same page.

When you use either a Naked Variable Reference or the (print:) macro to output the value of a variable…

(set: $apples to 6)

<!-- Using a Naked Variable Reference.. -->
You have $apples Apples.

<!-- Using a Macro.. -->
You have (print: $apples) Apples.

…a copy of that variable’s current value is injected into the page’s HTML structure. And that is why any change you make to that variable’s value…

(set: $apples to 6)

Reference: You have $apples Apples.

Macro: You have (print: $apples) Apples.

(link-repeat: 'Buy an Apple')[
	(set: $apples to it + 1)
]

…has no affect on the value being displayed on the page.

There are a number of different techniques you can use to update sections of the page, two of them being:

1: Using the (rerun:) macro to re-execute the contents of a Named Hook.

(set: $apples to 6)

Reference: You have |apples>[$apples] Apples.

Macro: You have |apples>[(print: $apples)] Apples.

(link-repeat: 'Buy an Apple')[
	(set: $apples to it + 1)
	(rerun: ?apples)
]

2: Using the (replace:) macro to replace the current content of a Named Hook.

(set: $apples to 6)

Reference: You have |apples>[$apples] Apples.

Macro: You have |apples>[(print: $apples)] Apples.

(link-repeat: 'Buy an Apple')[
	(set: $apples to it + 1)
	(replace: ?apples)[$apples]
]

note: I gave the Hooks the same Name as the variable they contained to make it clear what those Hooks represented, and to help me remember what they contained. But those Hooks could of been named anything else and would of still worked…

(set: $apples to 6)

Reference: You have |hiphop>[$apples] Apples.

Macro: You have |hiphop>[(print: $apples)] Apples.

(link-repeat: 'Buy an Apple')[
	(set: $apples to it + 1)
	(rerun: ?hiphop)
]

So if we applied the 1st technique to your own example…

(set: $pushes to 0)

(link-repeat: 'Push')[
	(set: $pushes to it + 1)
	(rerun: ?outcome)
]
|outcome>[{
	(if: $pushes is 1)[
		You have pushed the button one time. Nothing seems to happen yet.
	]
	(else-if: $pushes is 2)[
		As you push the button a second time, you notice a mechanic sound behind the wall.
	]
}]

note: The contents of the Named Hook is more complex this time, as it uses the (if:) and (else-if:) macros combined with a ‘counter’ variable to determine exactly what to display.

2 Likes

Okay that works out pretty well. 2 little questions remain to that techniques.

I want to use that about 10 times. Nut everytime i click on it, the explanation what happens now drops one line below. Since there is already something written on the page, this could make the page longer than expected. Is there a way it stays on the same line?

  1. I want to make 10 as a Limit. Can a make the “Push”-Button disappear after the limit of 10 is reached?

Anyway, thank you for your great help. May you have a great day. :slight_smile:

If you take Greyelf’s code and change it to the following:

(set: $pushes to 0)

|push>[(link-repeat: 'Push')[
	(set: $pushes to it + 1)
	(rerun: ?outcome)
]]
|outcome>[{
	(if: $pushes is 1)[
		You have pushed the button one time. Nothing seems to happen yet.
	]
	(else-if: $pushes is 2)[
		As you push the button a second time, you notice a mechanic sound behind the wall.
		(hide: ?push)
	]
}]

…you’ll get something what I think you’re trying to achieve. Notice that a hook |push>[ ] was added around the link. Also notice that a line of code (hide: ?push) was added on the last push condition in the outcome hook. You can hide and show hooks freely in Harlowe. This is a great technique to master.

Note: A shown hook looks like |hook>[ ] and a hidden hook looks like |hook)[ ]. I found this a little confusing at first so I’m mentioning it now. For further information, see the #macro_hide section of the Harlowe manual. In fact, it offers an example that really closely mimics what’s happening here.

I hope that helps.


When you start learning to program, you’ll notice patterns of logic. The basic patterns usually revolve around syntax, types of variables, conditions and loops and that will carry you through almost anything you want to achieve. Unfortunately, I have not been able to find a beginner friendly tutorial on programming in Harlowe, but I do encourage you to check out the Twine Cookbook and look at examples of the Harlowe code for all the cookbook scenarios. Eventually, those examples will become second nature. Each one is relatively short and carries a good lesson.

1 Like

Too sad i can’t give two Solution marks since it was a combination of youir both ideas.

Thank you very much for the help. Both of you.

About the programming. I tried to make my own website using HTML+CSS a few days ago with the help of a friend. And this friend also wanted to talk about syntax and variables and stuff. Maybe i should take some time, listen to her about that. ^^

1 Like

I just waited until Greyelf did all the heavy lifting, then I waited patiently… and swooped in with two lines of code to take all the glory. That was the plan all along. :wink:

Seriously though, we’re just glad to help.


Your friend sounds like she knows her stuff. Perhaps she might enjoy Harlowe and you two can work on things together. I find that those who already know programming can devour Twine story logic quite easily and it’s always good to have a wingman. Good luck!

I have to confess.

The description sentence still drops down everytime i click on push.
like its first

Push
You have pushed the button one time. Nothing seems to happen yet.

and when i click again its like:

Push

As you push the button a second time, you notice a mechanic sound behind the wall.

And doing that 10 times it would end up like:

Push
.
.
.
.
.
.
.
.
.
.
Something happens.

For explanation i use (if:) only for the fist one and (if-else:) for everything what follows, since twine says its made for multiple usage.

Am im doing anything wrong?

And about that friend. Shes studying development and helped me out a little bit on twine already but she doesnt seem to have much interest in that, wich is complety okay for tho. ^^

I see what’s happening and will get back to you when I’m at my computer again. I’ll need to test my code before presenting a solution. However, I believe each (if:)[ ] macro is creating <tw-expression> and <tw-hook> HTML tags and this is creating paragraphs of emptiness in the underlying HTML code.

We’ll get it sorted out.


Edit: Alright, here is something that should help:

{
|push>[(link-repeat: 'Push')[
	(set: $pushes to it + 1)
	(rerun: ?outcome)
]]<br>

|outcome>[
	(if: $pushes is 1)[
		You have pushed the button one time. Nothing seems to happen yet.
	]
	(else-if: $pushes is 2)[
		As you push the button a second time. Nothing happens again.
	]
    (else-if: $pushes is 3)[
		As you push the button a third time. Again, nothing happens.
	]
    (else-if: $pushes is 4)[
		As you push the button a fourth time. You notice a mechanic sound behind the wall.
		(hide: ?push)
	]
]
}

…you’ll notice that I wrapped everything in { } brackets. This causes all elements within to ignore any line breaks. However, when using this technique, you can use <br> tags to force a line break.

For some reason, placing the { } brackets inside the |outcome>[ ] hook didn’t work. This could be a bug in Harlowe. However, placing them outside seems to have solved the problem.


For more information on dealing with unwanted line breaks and spaces, refer to #markup_whitespace and the 3 other sections just below it. Unfortunately, this is a common problem in Harlowe and requires some mastery over when to expect this problem and how to remedy it. I do recommend going through some Harlowe tutorials to get a feel for coding. It’s tough to stop the momentum on developing a story to learn the programming language, but very worthwhile.

Let us know if you have any other questions. :slight_smile:

Okay, this really did it! I thank you like 8000 times and greyelf too!. :slight_smile:

1 Like