Howdy, Stranger!

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

Conditional Text - Choice Outcome [Snowman 1.1]

edited August 2015 in Help! with 2.0
Another way of phrasing this may be, "If X choice then display Y text". I'll do my best to contextualize the question. If the player chooses to do B (Passage B) instead of A (Passage A), how do I display the result of B in future passages? I'd need to check for this whenever the specified event is a subject.
Passage A: "Steve chose to punch Bob."

Passage B: "Steve did not choose to punch Bob."

Passage C: (display conditional text, A or B outcome)
If player chose A, then display "Steve and Bob are enemies." in Passage C. 

If player chose B, then display "Steve and Bob are friends." in Passage C.
I searched the 'Help! with 2.0' category for Snowman, but there wasn't much information; less than six pages total. I'd immensely appreciate any help in figuring this out. I'm not looking to make a complex CYOA game. (at least as far as JavaScript goes) I just need help getting started. Thank you for reading!

Comments

  • You can use a variable to track if Steve punched Bob or not.

    The following example if made up of four passages (Start, Passage A, Passage B, and Passage C)

    1. Start
    Snowman lets up store information within it's state collection, it makes this collection available to your passages via a s variable that you can extend. The following code creates a punchedBob variable which will default to false:
    Assign a default value to the variable being used to track if Steve choose to punch Bob.
    <% s.punchedBob = false %>
    
    Select which passage you want to go to:
    [[Passage A]]
    [[Passage B]]
    
    2. Passage A
    In this passage we change the value of the punchedBob variable to true because Steve punched Bob:
    Steve chose to punch Bob.
    <% s.punchedBob = true %>
    
    [[Passage C]]
    
    3. Passage B
    In this passage we change the value of the punchedBob variable to false because Steve did not punch Bob. This assignment is not totally necessary because the default value of the variable is false but it is a good idea to do this assignment anyway:
    Steve did not choose to punch Bob.
    <% s.punchedBob = false %>
    
    [[Passage C]]
    
    4. Passage C
    We test the current value of the punchedBob variable and display the relevant text:
    <% if (s.punchedBob) { %>Steve and Bob are enemies.<% } else { %>Steve and Bob are friends.<% } %>
    
  • edited August 2015
    Fantastic! Thank you! That works really well with binary outcomes. Now, how would it be done if there were three or more possible choices; a system that does not rely on true or false to determine the text used?
  • You could change the punchedBob variable to be a number or a sting instead:
    <% s.punchedBob = 0 %>
    <% s.punchedBob = 1 %>
    <% s.punchedBob = 2 %>
    <% if (s.punchedBob == 1) { %>Steve and Bob are enemies.<% } %>
    
    or
    
    <% s.punchedBob = "once" %>
    <% s.punchedBob = "twice" %>
    <% s.punchedBob = "every time you saw him" %>
    <% if (s.punchedBob == "twice") { %>Steve and Bob are enemies.<% } %>
    
    note: In Javascript a single equals sign '=' indicates assignment, where as a double equal sign indicates comparison.
  • Thank you very much, greyelf. I really appreciate your help on this. I've got a lot of work ahead; this is going to be of incredible value to me these next few weeks. So many choices!
Sign In or Register to comment.