tmedwards / sugarcube-2

SugarCube is a free (gratis and libre) story format for Twine/Twee.
https://www.motoslave.net/sugarcube/2/
BSD 2-Clause "Simplified" License
185 stars 42 forks source link

Add TwineScript version of `<<script>>`? #250

Closed tmedwards closed 4 months ago

tmedwards commented 1 year ago

Currently, the only way to simply execute TwineScript‍ code is to use the <<run>> or <<set>> macros. This works well for single-line code snippets, but is less than ideal for multi-line snippets.

Ideally, there should be a better way to handle multi-line TwineScript code snippets. For example, either:

Thoughts?

-- In SugarCube, TwineScript is simply sugared JavaScript. E.g., The TwineScript snippet $foo to true desugars to the JavaScript snippet State.variables.foo = true.

SjoerdHekking commented 1 year ago

I vote for option 2: it's faster to read/write, especially if you also allow for javascript, js and twinescript, tw, plus a lot less confusing for newer authors that might not understand arguments that well, e.g. script type javascript

greyelf commented 1 year ago

Why can't the current <<script>> macro just be altered to include support for TwineScript?

eg. what use-case(s) are there that require that the existing macro doesn't support TwineScript?

tmedwards commented 1 year ago

There is a non-zero chance that TwineScript may not desugar into JavaScript perfectly.

I'd prefer that end users who need/want JavaScript not have to worry about possible desugaring issues.

ChapelR commented 1 year ago

You could also do a flag/keyword on the existing script macro to make it execute TwineScript, instead of having two names, which might be better if you wanted to keep the <<script>> name for parity (such as it is) with HTML. Something like <<script twine>>...<</script>> maybe. Idk.

It's a good idea, though, I think.

In my dream SugarCube, it'd be cool to be able to do like <<run expression>>, or <<run>>expression<</run>>.

tmedwards commented 1 year ago

That was one of the options—well, not exactly that but the gist is the same.

 

In my dream SugarCube, it'd be cool to be able to do like <<run expression>>, or <<run>>expression<</run>>.

That's unlikely to work for expression type macros—edit: without more ambiguity than I'd like—but it's on my radar in v3 for argument types. Though the syntax would probably be a bit different. E.g.,

<<textbox $value />>

<<textbox $value>>
    /* Field was changed. */
<</textbox>>

This is one of those things that would work better, or more broadly, with a core syntax change—i.e., moving away from the <<…>> syntax.

ChapelR commented 1 year ago

That was one of the options—well, not exactly that but the gist is the same.

I guess I somehow blacked out for like 10% of reading the original issue, lol. That's my preference though.

Yeah, something like that would be cool in SC3!