sugarcube-2 icon indicating copy to clipboard operation
sugarcube-2 copied to clipboard

Spread syntax with story/temporary variables causes TwineScript error

Open AlyxMS opened this issue 1 year ago • 3 comments

Describe the bug. Using spread syntax without a space (I.E. [...$var]) causes issues. But using a space to separate does not. (I.E. [... $var])

To Reproduce: Example: Attempting to convert a Set to Array. $set is a Set variable.

<<set setup.setToArray = function (set) { return [...set] }>>
<<set _arr = setup.setToArray($set)>>
This would work.

<<set setup.set = $set>>
<<set _arr = [...setup.set]>>
This would work as spread is not used on a story or temporary variable.

<<set _arr = [... $set]>>
This works. A space is used to separate the spread syntax.

<<set _arr = [...$set]>>
This errors out "$set is not defined".

Expected behavior. Spread syntax should work with story or temporary variables even if there is no space separating them.

Project details.

  • SugarCube Version: 2.36.1
  • Compiler & Version: Tweego version 2.1.1+81d1d71

Desktop details.

  • OS & Version: Windows 10 Enterprise LTSC Version 1809
  • Browser & Version: Chrome 111.0.5563.66 (64 bit)

Additional context. Problem is rather minor, just posting it for good measure.

AlyxMS avatar Mar 24 '23 07:03 AlyxMS

Point taken, it's called spread syntax not "spread operator" :D Appreciate the fix!

AlyxMS avatar Mar 27 '23 01:03 AlyxMS

WAT? Oh. The edits. That's just for my own OCD. It is a syntax, rather than an operator, so call a spade a spade and all that.

tmedwards avatar Mar 27 '23 02:03 tmedwards

you must craft the perfect title before you close this and never look at it again

ChapelR avatar Mar 29 '23 01:03 ChapelR