Hi,
Still pretty new to all this. I haven't been able to find much guidance about how to splice an array in Harlowe. It would be useful to be able to change the value of an element in the middle of an array. E.g. I'm trying to do something like this:
Start
(set:$arraytest to (a:0,0,0,0,0,0,0,0,0))
(goto:"Splice Test")
Splice Test
{(set:$position to (random:0,8))
(set:$newvalue to (random:1,9))
}
Current array: $arraytest
(Link:"Change the element at position $position to $newvalue")[(set:$arraytest to (a:$arraytest.splice($position,1,$newvalue))]
Splice Test
... but of course it doesn't work and I've been reduced to just guessing and changing things randomly ^_^
Thank you!
EDIT:
Okay, I got more or less the effect I was looking for with ...
[(set:$array's $position to $newvalue)]
... although if anyone out there wants to explain splice in Twine for a newbie I'd still be grateful ^_^
Comments
According to those docs the splice function returns an array containing any deleted elements. so
Will set $arraytest to an array holding an array holding whatever is at location $position. BTW there was a bracket missing from your code.
To just change $arraytest you would need to use