Howdy, Stranger!

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

Remove element from an array

Hi there !

First of all : I'm french, so please, excuse my clumsy English....

I try to remove an element from an array ( using the element value, not his index)
On the wiki's Faq, I found this exemple for Twine 1 :
<<set $currentLoops.splice($currentLoops.indexOf($march),1)>>
For Twine 2 I change this into :
(set: $dests.splice($dests.indexOf($dest),1))
Witch actually works ! besides I got this error : "(set:)'s 1st value is an array, but should be an assignment operation."

Is this the good way to achieve this ? How I could get rid of the error ?

(I use the default Harlowe story format)


Comments

  • The <<set>> macro in the Twine 1 story formats supported the execution of Javascript expressions as well as doing variable assignments / manipulations.

    The Harlowe (set:) macro expects you to be assigning the result of the Javascript expression to a variable, which is why you get the error message. You can solve this by assigning the result of your expression to a dummy meaningless variable, as shown in the following example:

    (set: $dests to (a: "home", "shop", "school", "park"))
    Possible Destinations: $dests

    (set: $dest to "school")
    Your Destination: $dest

    (set: $dummy to $dests.splice($dests.indexOf($dest),1))
    Remaining Destinations: $dests
    If you want to save line space you could reformat the above like so:

    Possible Destinations: (set: $dests to (a: "home", "shop", "school", "park"))$dests

    Your Destination: (set: $dest to "school")$dest

    Remaining Destinations: (set: $dummy to $dests.splice($dests.indexOf($dest),1))$dests
  • Thank's a lot !
    It make sens now.
Sign In or Register to comment.