+1 vote
by (420 points)

Hello,

I am trying to get one of my pages to dynamically change the text variable that is displayed on the page, however I don't want to do it the way I am right now, where I am using: <<click>><<script>>state.display("")<</script>><</click>> as a link to refresh the page to show the correct text for the variable on the page.

Here is the link to my sample: Prototype 3    (navigate to where it says "Difficulty")

Is there a way to get this variable (on the same page) to update what is shown when the <<cyclinglink>> variable changes, without having to use this state.display script?

Thank you so much in advance.

1 Answer

+1 vote
by (8.6k points)
selected by
 
Best answer

You could try marking the fields with IDs (I used "difficultyName" and "difficultyDesc") and attach a click handler to your <<cyclinglink>> which sets their contents. Don't forget to set the contents initially, of course.

Additionally, I marked the <<cyclinglink>> macro with the "difficultyChooser" ID to make sure you can have more than one of those in the passage without the events getting fired for all of them. The resulting passage would look somewhat like this.

<p>Difficulty is currently: @@#difficultyName;$difficulty@@

Change difficulty to: @@#difficultyChooser;<<cyclinglink "$difficulty" "Easy" "Normal" "Hard">>@@ 

<<script>>
jQuery(() => {
	var showDifficulty = (diff) => {
		jQuery("#difficultyName").empty().append(diff);
		jQuery("#difficultyDesc").empty().wiki('<<if $difficulty eq "Easy">> In easy difficulty, enemies are easy to outmaneuver. The player is greatly favoured in luck draws. Extra stat points are rewarded for each level up. Characters will be very forgiving. Saves points and tips are provided regularily. <<elseif $difficulty eq "Normal">> In normal difficulty, enemies are more challenging, but no time restrictions are given during combat. Luck draws are balanced. Save points are given several times during each chapter. Tips are provided in critical situations. <<elseif $difficulty eq "Hard">> In hard difficulty, enemies are tougher and more cunning - they will fight you to the best of their ability. The player is handicapped in luck draws. Characters will remember every word you say to them. <warning>Warning</warning>: No save points will be provided! The story will autosave with your progression; there is no going back on any of your choices. <<endif>>');
	};
	jQuery("#difficultyChooser a.cyclingLink").click(() => showDifficulty(State.variables.difficulty));
	showDifficulty(State.variables.difficulty || "Easy");
});
<</script>>


@@#difficultyDesc;...@@



<<return>>
</p>

 

by (420 points)

Yes! Thank you, this was exactly what i was looking for. smiley

...