Howdy, Stranger!

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

Help with (set: $list) and (if: $list contains)

Hi!
So I am brand new at this - literally started today - and I am trying to get the lists to work. I noticed that if in one passage, I set the list to contain f.ex. a dagger, and then in the next passage, I set the list to contain f.ex. a sword - then the list starts over and the dagger disappears. This makes sort of sense to me, but I don't know how I get the list to contain both items - so that the dagger stays in the list, even though I add a sword.
I am using the command: (set: $list to "dagger") in the first passage, and the same one in the next passage, just replaced "dagger" with "sword". It does seem fairly obvious that this would restart the list.
I figured I could either put both item in the list in the next passage - this solution seems very impractical and very confusing as soon as the story gets more complex. However, I don't even know how to put multiple items in one (set: $list to)-command.
Or maybe there is some command that makes the previous items in the list stay there, even when new ones are added?
I am using Harlowe 1.1.1

And in advance; thank you soooo much for your help! I really do appreciate it!

Comments

  • These are variables:
    $list
    $array
    $foo
    $bar
    $baz
    $helloWorld
    $variable
    $asdf
    

    And so forth. What you name the variable has no effect on how you use it.

    What you're calling a "list" is called a "dataset" or "datamap" in Harlowe.

    Datasets look like this:
    (set: $weapons to (dataset: "sword", "axe", "dagger"))
    

    Dataset and datamap are both covered very briefly at the bottom of the Harlowe markup syntax page here: http://twine2.neocities.org/

    Working with arrays is complex and there is a learning curve. I don't have time to go into it for Harlowe, but it will require some time research.

    Many a mind has broken trying to create inventories in Twine, but take a look at this link: http://twinery.org/forum/discussion/2823/simplest-way-to-do-an-inventory-in-twine-2

    Hope that helps!
  • As stated by Sharpe, the name you give a variable has no effect on what capabilities it has, on the other hand the datatype stored within the variable does.

    The following will demonstrate some of the ways to use the array datatype.
    The following creates a variable named var contains an empty array.
    (set: $var to (array:))
    
    The following adds a "dagger"  to the array.
    (set: $var to it + (array: "dagger"))
    
    The following adds a "sword" to the array.
    (set: $var to it + (array: "sword"))
    
    The following displays the currently content of the array.
    (print: $var)
    
    The following removes the "dagger" from the array.
    (set: $var to it - (array: "dagger"))
    
    The following checks to see if the "dagger" is still in the array.
    (if: $var contains "dagger")[The array contains a dagger!]
    (else:)[No dagger found in the array]
    
  • edited November 2015
    @greyelf
    Thank you so much for that!
    Is it possible to use an (if:) here? Like if the array contains a dagger, then something else or something extra will be shown in the next passage?
  • @greyelf
    Okay, never mind, that was stupid. Just checked the last sentence in your answer. I am sorry! Thank you very much!
Sign In or Register to comment.