I am using Sugarcube 2.6.2 in Twine 2.
So I figured it's about time I tackled that elephant in my IDE.
I've been researching into Javascript syntax recently because I want to figure out how to add a javascript function to my story, but now my issue lies in the interaction between twine and javascript.
I don't have any experience with combining code of different languages, so I'm a bit lost and most posts I've looked at relating to it are coming up greek to me.
So, my questions are thusly:
1) For example's sake, let's say I want to add a function that does something like the following pseudocode:
2) How do I call a javascript function in Twine 2? Again, for example's sake, let's say I call the above function, "foo", in this passage below:
So I figured it's about time I tackled that elephant in my IDE.
I've been researching into Javascript syntax recently because I want to figure out how to add a javascript function to my story, but now my issue lies in the interaction between twine and javascript.
I don't have any experience with combining code of different languages, so I'm a bit lost and most posts I've looked at relating to it are coming up greek to me.
So, my questions are thusly:
1) For example's sake, let's say I want to add a function that does something like the following pseudocode:
function foo($myStoryVariableObject) { if $myStoryVariableObject.name == "Jeremy" { print("The evil wizard transforms Jeremy into a chicken!") $myStoryVariableObject.status = "polymorphed" } else { print("Candy uses one of her spell slots to counter the wizard's spell!") $myStoryVariableObject.spellSlots = $myStoryVariableObject.spellSlots - 1 } }How would I code this? More specifically, how do I send a story variable to javascript and access it within javascript? Are there any interactions/bugs/differences between Story objects and javascript objects that I should be aware of?
2) How do I call a javascript function in Twine 2? Again, for example's sake, let's say I call the above function, "foo", in this passage below:
The evil wizard waves his hands and chants arcane words! Your prepare to roll out of the way, but he aims at your companion! <<foo($companion)>>What would be the correct way of calling the function?