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

Reserved words 'to' and 'is' on <<set>> macro causing interference with template literals #123

Closed dltwgm closed 3 years ago

dltwgm commented 3 years ago

Describe the bug I set out to create a character object (adventurer) which could be procedurally fed multiple dialogue lines to be customized within the object itself, via string interpolation using the template literal backtick ( ). The function would then at runtime be able to generate the proper phrase given global variables, or those on the object itself, even if they've been modified during play. The issue is that using the macro <> is causing interference with the reserved words "to" and "is".

The code would go like this:

<<set $namePicked to "Nathan">>
<<set $jobPicked to "barkeep">>

<<set $adventurer = {
    name : $namePicked,
    job : $jobPicked,
    introduction : function(){
            return `My name is ${this.name}. I used to be a rising ${this.job} until I was recruited to be an adventurer.`;
    }
}>>

<<print $adventurer.introduction()>>

Expected behavior. It was expected that the $adventurer.introduction() function would return the string "My name is Nathan. I used to be a rising barkeep until I was recruited to be an adventurer." but it instead returns the string "My name === Nathan. I used = be a rising barkeep until I was recruited = be an adventurer." (which, granted, is pretty funny).

Screenshots. This is what the user would see. image

To Reproduce: The code above should work to reproduce the issue.

Project details.

Additional context. Is this a pure question of "Sugarcube doesn't support template literals", or should there be a better way of handling this kind of issue?

tmedwards commented 3 years ago

This should be addressed by commit 5d7bb7a from 2mo ago, which has yet to be published but will be in the next release.