Howdy, Stranger!

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

Creating a Binary Decision from Several Options (then eliminating those options)

Finally been thrown for a loop on a problem. First post, but lurking for a few months.

The idea is this: I'd like for a player to visit a location and randomly see 2 people out of a possible 5. They can then choose which person to talk to, which takes them to separate passage for that conversation.

Next, I'd like to make the chosen person no longer show as an option at this location once their option has been chosen. I still want to have a choice and show 2 people out of the remaining options.


I've attempted creating a datamap that includes the possible passages, but Harlowe doesn't like that code. I've tried creating an array and using Either to assign a random number to a variable and then coding it to pump out a different location based on this, then... Well, it would get labor intensive. But, there's gotta be something aside from pages of repeated entries to solve this problem.

Thanks!
(Using Harlowe 1.2.3, Twine vers. 2.0.11)

Comments

  • edited April 2017
    Try something like this:

    In a startup tagged passage:
    ::init [startup]
    {(set: $characters to (a: "James", "Billy", "Sarah", "Nick", "Ann"))
    (set: $pick1 to 0, $pick2 to 0)
    (set: $firstChar to "error", $secondChar to "error")}
    

    In the passage in question:
    ::repeat
    {
    (set: $lt to $characters.length)
    (if: $lt >= 1)[
      (set: $pick1 to (random: 0, ($lt - 1) ))
      (move: $characters's ($pick1) into $firstChar)
      
      (if: $lt - 1 >= 1)[
        (set: $pick2 to (random: 0, ($lt - 1) ))
        (move: $characters's ($pick2) into $secondChar)]
        
      (else:)[
        (set: $secondChar to "")]]
        
    (else:)[
      (set: $secondChar to "", $firstChar to "No one seems to be here ...")]
    }
    (print: $firstChar)
    (print: $secondChar)
    
    [[repeat]]
    
    ​
    

    You could set up to go the conversation passages using something like:
    [[(print: "talk" + $firstChar)<-Talk to (print:  $firstChar)]]
    

    So you'd need to delete the resulting passages with gibberish names and create passages with names like 'talkSarah' or 'talkJames', which is probably what I'd do personally. If you do so, note that you'll need additional control logic to prevent 'talk<-Talk to' links and such from being created. You could also create an array of objects, but I'm not 100% sure how to make that work in Harlowe.
  • If you use a (link-goto:) macro instead of a markup-based link then you wont have to delete any 'passages with gibberish names', nor will you end up with broken passage connection arrows on your Passage Map.

    The following is the macro equivalent of the markup link example by @Chapel:
    (link-goto: "Talk to $firstChar", "talk" + $firstChar)
    
  • Thanks for the tip on the link-goto (although it doesn't create an arrow for me between passages or a new passage, it'll save a few key strokes.)

    Sorry if I'm taking bits and pieces of what you have said, and using them differently, but here is my amateur code. I used three variables just to make sure it worked and shuffled them.
    {
    (set: $cool to (a: 1,2,3))
    (if: $Ttwo is "visited")[(set: $cool to it - (a: 2))]
    (set: $cool to (shuffled: ...$cool))
    (set: $option1 to $cool's 1st)
    (set: $option2 to $cool's 2nd)
    
    (if: $option1 is 1)[There is an old man in the corner. (link-goto: "Talk to him.", "T1")]
    (if: $option1 is 2)[There is a nice lady. (link: "Talk to her.")[(goto: "T2")]]
    (if: $option1 is 3)[There is a dog. (link: "Talk to it.")[(goto: "T3")]]
    <br>
    (if: $option2 is 1)[There is an old man in the corner. (link-goto: "Talk to him.", "T1")]
    (if: $option2 is 2)[There is a nice lady. (link: "Talk to her.")[(goto: "T2")]]
    (if: $option2 is 3)[There is a dog. (link: "Talk to it.")[(goto: "T3")]]
    }
    

    On passage "T2", I simply set the variable as "visited" and upon return, I only see the other two options listed forever. Which is perfect.

    I'll have to learn the Move macro at some point, but this allows for no use of it.

    Thanks again, I appreciate the thought-process and if you have any suggestions on streamlining this, let me know.

Sign In or Register to comment.