0 votes
by (640 points)
edited by
SO

In my passage there is a <<link>>

When the reader clicks on it i want different things to happen depending on the value of a variable (let's call it $test):

If $test is less than 6, then I want it to go to passage 2.
If $test is more than 6, the I want two things to happen:

1. The <<link>> should deactivate, and change its text to something else

2. The <<link>> should contain code to change the value of $test. (for example: $test -= 6)

How do i do this?

Thanks guyz

2 Answers

0 votes
by (23.6k points)
selected by
 
Best answer
<<nobr>>
<<if $growthVert == true>>
	"The text you want it to turn into"
<<else>>
	<span id = "verGrow">
	<<link "Grow Vertically (6 energy)">>	
		<<if $test < 6>>
			<<goto "passageName">>
		<<else>>	
			<<replace "#verGrow">>
				"The text you want it to turn into"
			<</replace>>
			<<set $growthVert = true>>
			<<set $test -= 6>>
		<</if>>
	<</link>>
	</span>
<</if>>
<</nobr>>

 

by (640 points)
This works very well for all my intents and purposes. Thank you!
+1 vote
by (68.6k points)
Could you rephrase that?  I'm not exactly sure what you're asking for.  I'm getting the gist of some of it, but....
by (640 points)
Sure

In my passage there is a <<link>>

When the reader clicks on it i want different things to happen depending on the value of a variable (let's call it $test):

If $test is less than 6, then I want it to go to passage 2.
If $test is more than 6, the I want two things to happen:

1. The <<link>> should deactivate, and change its text to something else

2. The <<link>> should contain code to change the value of $test. (for example: $test -= 6)

How do I set this up.

Let me know if it's still unclear.
by (68.6k points)

If $test is less than 6, then I want it to go to passage 2.
If $test is more than 6, the I want two things to happen

 That leaves a value of exactly 6 unaccounted for, so I'm assuming one of those should include "or equal to".  Which one?

 

1. The <<link>> should deactivate, and change its text to something else

Can the player ever return to that passage with the link?  If so, does "deactivate" mean for all time or only for the current instance—i.e. should the link be active again when they return or still be switched out with the alternate text?

by (640 points)
edited by

If $test is more than 6, the I want two things to happen

Should also apply to $test = 6

 

Can the player ever return to that passage with the link?  If so, does "deactivate" mean for all time or only for the current instance—i.e. should the link be active again when they return or still be switched out with the alternate text?

The link should be permanently deactivated if used when $test >= 6, but not in other cases.

Here's a picture that might help explain things: https://imgur.com/9ayurGY

IN this scenario, the option shown in the red box, costs 6 energy to be implemented.

When clicking on the link, I want to consider the amount of energy the player has. In this case, 0. 

Since the player has insufficient energy, I want the link to lead to another passage. In this case the link should not be deactivated.

If the player has enough energy, then I want the link to deactivate, change it's text, and change a variable (basically run a script which deducts energy cost from total energy available).

by (68.6k points)

Before I give my answer, a question.  Instead of going to another passage to handle insufficient energy, why not simply either show some text instead of the link indicating they don't have enough energy or have the link output the insufficient energy message right there?  What you're wanting to do is a little convoluted.


Anyway. Something like the following should work.

<<if $growVertDone>>
\You already did this!
\<<else>>
\<span id="grow-vertically">
\<<link "Grow Vertically (6 energy)">>
	<<if $test lt 6>>
		<<goto "Some Passage">>
	<<else>>
		<<set $energy -= 6>>
		<<set $growVertDone to true>>
		<<goto `passage()`>>
	<</if>>
<</link>>
\</span>
\<</if>>

You may not like that it goes back to the same passage to handle the link replacement, but that's the easiest way to accomplish it.  Elsewise you'd need to duplicate the replacement text or something else convoluted.

by (640 points)
This accomplishes most of what I want but having it link back to the same passage does cause some issues. I did end up changing it so the link shows 'insufficient energy' right there on the passage as opposed to another passage altogether. Thanks for all the help. Learned some code today!
...