cyrusfirheir / twee3-language-tools

[ VSCode extension ] Syntax highlighting and programmatic language tools for Twee 3, and Twine 2 storyformats.
https://marketplace.visualstudio.com/items?itemName=cyrusfirheir.twee3-language-tools
MIT License
47 stars 16 forks source link

Optional warning for usage of variable in receiver location #65

Open MinusGix opened 2 years ago

MinusGix commented 2 years ago

It is a common mistake to write a textbox like <<textbox $name "default">> where in fact, the author meant to write <<textbox "$name" "default">> so as to have the value stored in the variable $name.
Yet, this cannot simply be errored upon, because it isn't uncommon for users to do something like:

<<if $cond>>
    <<set $target = "$player_name">>
<<else>>
    <<set $target = "$npc_name">>
<</if>>
<<textbox $target "default">>

(especially in things like widgets, where you will be accepting a receiver yourself!)
But, for users where this isn't something that they want to do, it could be beneficial to be able to know that they'll avoid mistyping and using a variable directly rather than a string version of it.
Theoretically, this way of writing textbox seems to work: <<textbox '$target' "default">> (assume the single quotes are tilde, for the expression syntax), and so the warning could encourage the user to write out variables which hold references (like $target) with the expression syntax instead. Not perfect, but if it was an optional warning, then that would give an out for those who want to avoid the potential common bug while still using the feature.