Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

[Sugarcube 2.16.0] How to display links based on player action without a page reload?

I am wondering how to go about having n links showing one of them at a time based on user interaction without a page refresh/load.

As an example:
<<set _doorLocked to false >> 
<span id="action-text"></span>

<<if _doorLocked>>
	<li><<link "Unlock the Door">>
			<<replace "#action-text">>You unlock the door.<</replace>>
			<<set _doorLocked to false>>
		<</link>>
	</li>
<<else>>
	<li><<link "Lock the Door">>
			<<replace "#action-text">>You lock the door shut.<</replace>>
			<<set _doorLocked to true>>
		<</link>>
	</li>
<</if>>

Now this obviously won't work as is due to conditionals being processed on page rendering. I'd like to be able to either show the unlock or the lock links and execute the necessary code based on these actions without having to do a page reload if at all possible.

I am using Twine 2.1.1 and Sugarcube 2.16.0.

Comments

  • edited March 2017
    There are several ways you could go about it, the following is one:
    <<set _doorLocked to false>>\
    <span id="action-text">The door is unlocked.</span>
    
    <span id="action-link"><<link "Lock the door">>
    	<<if _doorLocked>>
    		<<set _doorLocked to false>>
    		<<replace "#action-text">>You unlock the door.<</replace>>
    		<<replace "#action-link>a">>Lock the door<</replace>>
    	<<else>>
    		<<set _doorLocked to true>>
    		<<replace "#action-text">>You lock the door.<</replace>>
    		<<replace "#action-link>a">>Unlock the door<</replace>>
    	<</if>>
    <</link>></span>
    
  • There are several ways you could go about it, the following is one:

    Thank you as always, TheMadExile.
Sign In or Register to comment.