Howdy, Stranger!

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

Send Player to Specific Passage (Sugarcube/Responsive)

For my game, I'm trying to use the button macro in a very specific way. I see there are ways for the player to enter their own information; however, I want the player to enter a code/key word, and send them to a different passage depending on what they typed. So, if they typed "A", they'd to to Passage A, and if they typed "B", they'd go to Passage B. Is there any way to do this?

Comments

  • edited May 2015
    The best way to do this is to send them to one passage that contains all results so you remove the need for separate answer passages. E.g.:
    <<textbox "$variable" $variable "passage">>
    

    This textbox will update the $variable with what the player types, then sends them to passage. Then in passage you would have results for A, B and failure:
    <<if $variable is "A">>Hello A!<<elseif $variable is "B">>Hello B!<<else>>Please enter a valid selection.<</if>>
    

    If you really, really want to use different passages, you can use a <<goto>> macro in a transitional passage to direct the player based on a variable, eg. in passage referenced above where the player arrives after entering text, instead of any text, you would have:
    <<if $variable is "A">><<goto "PassageA">><<elseif $variable is "B">><<goto "PassageB">><<else>><<goto "textentry">><</if>>
    

    That way as soon as the passage loads, the player is redirected to a new passage based on the variable set. This gets you the results you are after but it is not as efficient as putting everything in one passage.
  • A couple of small additions to what @Claretta posted:

    1. Remember to assign a default value to your $variable before using it in the <<textbox>> macro, this should be done in your StoryInit passage.
    This will stop it showing "undefined" when the textbox is displayed.
    :: StoryInit
    <<set $variable to "">>
    
    :: Ask User Question
    Where do you want to go?
    <<textbox "$variable" $variable "Check Answer">>
    

    2. One issue that can happen whenever you compare user input to a known value is that the user may enter a value using different casing than what you were expecting:

    eg. your checking for "Hello" and the user enters "hello"

    To get around this issue you should convert whatever the user enters to lowercase before comparing it to a known value:
    :: Check Answer
    <<set $variable to $variable.toLowerCase()>>
    <<if $variable is "a">>Hello A!<<elseif $variable is "b">>Hello B!<<else>>Please enter a valid selection.<</if>>
    

    3. If you do decide to get the user to enter actual passage titles, then remember that passage titles are case sensitive. So you will again need to convert their input to lowercase before using their input within a <<goto>> macro, you will also need to make all the titles of the passages that they can go to lowercase.
    eg. The user inputs "The Beach"
    :: StoryInit
    <<set $passage to "">>
    
    :: Ask User Question
    Where do you want to go?
    <<textbox "$passage" $passage "Check Answer">>
    
    :: Check Answer
    <<set $passage to $passage.toLowerCase()>>
    <<goto $passage>>
    
    :: the beach
    This is the passage the user ends up seeing.
    
  • @Claretta and @greyelf: Thank you both!
  • @Claretta and @greyelf: I'm having some trouble figuring out how to implement the code. Could you possibly write an example?
  • edited May 2015
    What specifics are you having trouble with? The code I wrote is the most comprehensive example I can think of, so, just on the face of it, can't think of how to make it more clear.
  • Is the format of my examples causing the confusion?

    They are written using Twee notation, where a line starting with a double colon :: indicates the start of a new passage, and the text following directly after the double colon is the title of the new passage. The text on all the lines below one containing a double is the contents of the new passage until either another double colon is encountered or the example ends.
  • @greyelf: Alright, thank you. Trying to implement it now.
  • Man, I completely forgot to report back.
    I got it to work! Thanks again, @greyelf and @Claretta for your help. :)
Sign In or Register to comment.