error message wouldn't explain what is wrong

i keep getting this message and i dont understand why

Error: <<set>>: bad evaluation: Invalid or unexpected token
<<set $ps1 to { name: “Lammar”, race: “Lammergeier”, statboost: “$armor += 5”, undostats: “$armor -= 5”, action: “Bite”, type: "Piercing", script: “fill in later” }>>

im making a combat system where the player character can shapeshift into the form of his allies, so i was trying to get something going like this where id be able to just call this variable as needed like in buttons (EXAMPLE: <<button $ps1.action "NEXT TURN">> ), but when i try to set this varible i get an error message they doesn’t tell me exactly whats wrong with it for some reason, so heres my code in case anyone else can see whats wrong.

<<set $ps1 to {
name: “Lammar”,
race: “Lammergeier”,
statboost: “$armor += 5”,
undostats: “$armor -= 5”,
action: “Bite”,
type: "Piercing",
script: “fill in later”
}>>

Curly quotes? I’m pretty sure you want straight quotes, not curly ones.

1 Like

String literal values like the “Lammar” being assigning to the name property of the Generic Object contained in the $ps1 variable have to be delimited with either standard single-quotes ' or standard double-quotes ". Typographical (Curvy) quotes like & or & " can only be placed inside a String literal value.

/* valid String delimiters */
<<set _variable to 'string delimitated with single quotes'>>
<<set _variable to "string delimitated with single quotes">>

/* Strings containing Typographical quotes */
<<set _variable to 'Jane said ‘blah blah blah’ to Mary'>>
<<set _variable to 'Jane said “blah blah blah" to Mary'>>
<<set _variable to "Jane said ‘blah blah blah’ to Mary">>
<<set _variable to "Jane said “blah blah blah" to Mary">>

So it has to use " or ’ but not “ or ‘? How would I achieve that via keyboard? It never required that before in other variables I’d have set in the same way, if you need I can share examples of stuff I have that’s written similarly that work

On a standard US based keyboard the standard single-quote ' key is directly to the left of the ENTER key, and that same key combined with the SHIFT key produces the standard double-quote ".

If I add the code example you supplied..

<<set $ps1 to {
name: “Lammar”,
race: “Lammergeier”,
statboost: “$armor += 5”,
undostats: “$armor -= 5”,
action: “Bite”,
type: "Piercing",
script: “fill in later”
}>>

…to a new Twine 2.x project, that has been configured to use the SugarCube 2.x story format I get the same error as you do. However, if I simply replace the Typographical (Curvey) double-quote in your example with standard double-quotes…

<<set $ps1 to {
name: "Lammar",
race: "Lammergeier",
statboost: "$armor += 5",
undostats: "$armor -= 5",
action: "Bite",
type: "Piercing",
script: "fill in later"
}>>

…the error message no longer appears.

Are you writing your code:

  • in the Passage Editor of the Twine 2.x application.
  • in a Text Editor, like Visual Studio Code (VSCode).
  • in a Word Processor application, like Microsoft Word or Google Docs

…because if it is in one of the first two of the above, then using the relevant quote keys on the keyboard should produce standard single ' and double " quotes.

If you are using the 3rd option listed above then often such applications have a configurable mode where Standard quotes are automatically replaced with Typographical ones. Which is one reason why such applications aren’t good to write code in.

I just type dircetly into the passage editor of the twine application, which is strange because i looked at my quotes, deleted them, retyped them, and it worked. So heres what happened, funny story, i think this was all because I was away from my computer once and wanted to code, so i just typed it up into a google doc to be pasted later when id get home, hence why i was getting those ones instead of the ones that sugarcube would normally give me!

Thanks for the help, its working like a charm now!

1 Like