Quantcast
Channel: Twine Forum
Viewing all articles
Browse latest Browse all 3830

How do I copy an array in Sugarcube 2?

$
0
0
(I'm using Sugarcube 2 in Twine2)
I've setup the array $opponent and want to copy it to a temporary variable that I can manipulate without changing the source variable.

I tried this:
<<set $opponent to [1,2,3,4]>>
<<set $templist to $opponent>>

But if I then use the splice-function I also change $opponent as in:
<<set $templist.splice($templist.indexOf(4),1)>>
<<print $opponent>> --> 1,2,3

But if I use: <<set $templist to []+$opponent>> this happens with the random()-function:
<<print $templist.random()>> --> ,

So how do I copy an array with only the numbers and not the commas?
Thank you.

Viewing all articles
Browse latest Browse all 3830

Trending Articles