Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Twine variables in Javascript (unusual problem)

Here's the code that won't work in Sugarcane:

Twee (inside of StoryInit)

newFruit = ""
<<set $fruit = []>>
<<set $fruit.push("Apple")>>
<<set $fruit.push("Orange")>>

When I pop <<$fruit>> into a passage, it appropriately returns Apple,Orange ...So that part works. The next part, not so much.

Javascript (inside of a macro that otherwise works):

state.history[0].variables["newFruit"] = ["Grape","Plum"]; (Twee: <<$newFruit>> returns Grape,Plum)

var oldFruit = state.history[0].variables["fruit"];
state.history[0].variables["newFruit"] = oldFruit;

When I do <<$newFruit>> It now returns 0.

I even tried this:

state.history[0].variables["newFruit"] = state.history[0].variables["fruit"];

and <<$newFruit>> still returns 0

What am I doing wrong? :(

/Misty

Comments

  • Can the answer be that state.history[0].variables only works on strings and not arrays? If that's the case, how can I access a twine array via JavaScript?
Sign In or Register to comment.