Howdy, Stranger!

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

Question prompt + goto= password system

I wanted to have a password/passcode system where a question is asked and the typed out answers leads to specific passages.

This part seems to work.

<<set $answer = prompt ("question")>>

<<if ($answer = "Answer 1")>> <<goto "Passage 1">> <<endif>>
<<if ($answer = "Answer 2")>><<goto "Passage 2">> <<endif>>

and now I wanted to add a "else" option that kind of looks like

<<else>> <<goto "passage 3">> <<endif>>

But it is not working, it sends the correct and incorrect answers to "passage 3".

Possible issues could be with "=" vs "is", not using if-> elseif -> else pattern, how each line does or does not need a <</if>> or <<endif>>..... I don't know.

Comments

  • With a little help from my comp science friend, this should work now.

    <<set $answer = prompt ("question")>>

    <<if ($answer = "Answer 1")>> <<goto "Passage 1">>
    <<else if ($answer = "Answer 2")>><<goto "Passage 2">>
    <<else>> <<goto "passage 3">> <<endif>>

    Now I can have people skip to the later passages without having to go through the boring stuff.
  • In Javascript a single equals sign '=' means assignment, so in your above two code examples when you write $answer = "Answer 2" you are telling the story format to assign the value "Answer 2" to the variable $answer.

    If you want to compare a variable to a value withing a <<if>> or <elseif>> then use either the "is" key work or double equal signs "==", so the above should be changed to:

    <<if ($answer is "Answer 1")>>

    or

    <<if ($answer == "Answer 1")>>
    To help with the whole single or double equals signs issue I suggest changing your <<set>> macros to use the "to" key word:

    <<set $answer to prompt("question")>>
Sign In or Register to comment.