Howdy, Stranger!

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

twine newbie

Hello

hope you will understand me, i 'm french teacher not so good in english
i just start twine. Not so good in programs but motivated.

Want to use it with my students ( 11 years old childs )
To be fun i will let them write but want to make a fun system.
i want to introduce simple rules.

in forums i took :

<<set $inv = ["Dagger", "Shield", "Potion"] >>
for exemple, to start an inventory

<<set $inv.remove('Potion')>>
and a script with to remove a potion for exemple from the inventory

and the way to print the inventory
<<print $inv.join("\n")>>

i don't write all but it s OK

In a passage if i want them to find a new object to add to the inventory
i ve done it with :
<<set $inv.push("new object")>>

it s ok with
<<print $inv.join("\n")>>
new object appear


BUT each time i go to the passage the new object come again in my inventory
how to make it appear just once ??

or with a message : you have already that object ?

Thank's and sorry for my poor english

Comments

  • Based on the examples you gave I believe you are using the SugarCube story format.

    To check if an array $variable contains a value you can use SugarCube's contains function. So if you want add "new object" to your $inv variable only once you could do the following:
    <<if not $inv.contains("new object")>>
    <<set $inv.push("new object")>>
    <</if>>
    
    ... or if you want to show a message instead:
    <<if $inv.contains("new object")>>
    You already have the new object.
    <<else>>
    <<set $inv.push("new object")>>
    <</if>>
    
  • Quick and efficient !
    Thank you
Sign In or Register to comment.