Hi everyone. Just got started with Twinery. Tried to search for this but couldn't find it. I am using Twinery 2.0.11 with the default packaged Snowman 1.3.0 format.
How do I reference a variable/function defined from another room?
I am thinking of having an initial "room" which will just define my code's functions and variables. Say an init room. Inside this I will have various functions like getPlayerHp, getPlayerInventory, damagePlayerHp and want them to be referable from other points in my story.
In a few tutorials the "state" and "state.history" objects are referenced but when I try to use this in my code it states it is not defined.
Is there an object I can use as a global hook as a unifying reference point?
Is there anything wrong with assigning most of my unifying code to say the "window" object?
Thanks
Comments
Snowman's documentation is brief but it does include how to reference story variables. The following first shows how to assign a value to a story variable named health and then how to output the value in a passage.
re: reference a function
Custom JavaScript should be placed within the dialog accessed via the Edit Story Javascript menu item.
All functionality defined in the Story Javascript area has a local scope which means that it can not be referenced from other passages, one common method used to increase the scope to global is to attach that code to the global window object.
I suggest using a Namespace like the one defined in the MDN JavaScript Object Management page to store your custom Javascript, the only change you will need to do is to attach that namespace to the window object.
a. Define the Namespace and a test function: b. Call test function within a passage: