Howdy, Stranger!

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

[Twine 1.4.2][Sugarcube-2] Password System and Age restriction

edited June 2017 in Help! with 1.x
Hello, It is Me Again asking a stupid question.

>How do I add a Password System on Twine 1 with Sugarcube-2

My Old Code:
--
<<set $answer = prompt ("Please Input A Password To Continue.")>>

<<if ($answer is "butimletired")>>Debug
<<else if ($answer is "0100000101110010011010010111001101100001")>><< Secertroute >>
<<else if ($answer is "IHATETHISGAME")>><< Commentary >>
<<else>> Start <<endif>>
--

Worked Under Sugar Cane. I recently moved on to Sugarcube-2 and the now it leaves me with this error:

--
<<set>>
<<if>> ERROR: <<if>>: <<else>> must be a final clause.
--

I assumed it meant change <<endif>> to <</if>> but it still shows up.
......


This is might be tricky, but I want a variable that asks for your age. if your age is under 18 it will kick you back to Start or even exit the game


Comments

  • You need to state the name and full version number of the Story Format you are using, as answers can be different for each one. I will assume you are using v2.18.0

    You can use the <<textbox>> macro to ask the Reader to supply an answer, the <<button>> macro to know when to check their answer, and the Javascript <String>.trim() function and the <String>.toLowerCase() function to format the String value the Reader enter in a way it can be consistently checked against a set of expected responses.

    If no answer was supplied you can use the UI.alert() function found in the UI API section to prompt the Reader for one, and once it has been determine that a correct answer has been supplied you can use the <<goto>> macro to send the Reader to the relevant next passage.

    The combination of the above would look something like the following code:
    <<set _answer to "">>
    
    Please input a Password to continue.
    <<textbox "_answer" "">>
    
    <<button "Check Password">>
    	<<if _answer is "">>
    		/% They have not supplied an answer. %/
    		<<script>>UI.alert("You did not supply a password!");<</script>>
    	<<else>>
    		/%
    			Remove extra white space from both ends of the answer then
    			convert it to lowercase. %/
    
    		<<set _answer to _answer.trim().toLowerCase()>>
    
    		/%
    			Check if one of the correct answers was supplied,
    			otherwise send them to the Start passage. %/
    
    		<<if _answer is "first correct answer">>
    			/% Send the Reader to the next relevant passage. %/
    			<<goto "First Correct Answer Passage">>
    
    		<<elseif _answer is "second correct answer">>
    			/% Send the Reader to the next relevant passage. %/
    			<<goto "Second Correct Answer Passage">>
    
    		<<elseif _answer is "third correct answer">>
    			/% Send the Reader to the next relevant passage. %/
    			<<goto "Third Correct Answer Passage">>
    
    		<<else>>
    			/% Send the Reader to back to the start. %/
    			<<goto "Start">>
    		<</if>>
    	<</if>>
    <</button>>
    
Sign In or Register to comment.