inkle / ink

inkle's open source scripting language for writing interactive narrative.
http://www.inklestudios.com/ink
MIT License
4.14k stars 493 forks source link

Dynamic tags appear to not update in JS #853

Open tessaSAC opened 1 year ago

tessaSAC commented 1 year ago

I've been updating CSS based on dynamic tags, but they only appear to interpolate on the inkle side of things and not in the JavaScript.

For example:

~ temp character = "Kirby"
# LABEL: { character }
VAR character = "Kirby"
# LABEL: { character }

In both cases, these populate in Inky/in the gameplay text correctly, but when printing them in the JavaScript, show { character } rather than Kirby.

tessaSAC commented 1 year ago

Update: I also tried

~ temp tag = "LABEL: { character }"
# { tag }

and

VAR character = "Kirby"
VAR tag = "LABEL: { character }"
# { tag }

and those didn't work either (first one didn't interpolate, same as before; second one resulted an error about putting logic in a string)

Selsynn commented 1 year ago

So I don't know how it should work. Several years ago, like two (and before 1.0 version of ink, it may not work) we made this code in a game jam

    ~timedActionID1 = "YouR Value"
     #resolveItem: timedActionID1

The timedActionID1 is a VAR that holds your value. After that there is the tag: name of the variable. However it does not work out of the box, and we had to create a special handling for it: the js went to fetch the value of the variable of the name it had. (the following is in the part of the )

        let itemId = window.STORY.story.variablesState[`${value}`];

that's the part where it transform the value of the literal timedActionID1 to the one that was variable from the ink text just over. Because JS. Once you have it, you can do whatever you want with it.

So for it to work, you have to do some logic in the js to handle the tag, and you have to be VERY careful to write exactly the name of the variable you want. But last I checked, it worked.

(especially you may have to rewrite how to read the current variable state, I think that changed., but the trick to interpret the value itself with the [`${value}`] should still work the same, as it's pure js)

benjaminpstern commented 1 year ago

This is also happening in C#. For example, # {RANDOM(1, 4)} resolves in the ink player to a number, but when calling story.currentTags in C#, it just gives "{RANDOM(1,4)}"