klembot / twinejs

Twine, a tool for telling interactive, nonlinear stories
https://twinery.org
GNU General Public License v3.0
2k stars 295 forks source link

<<script>> macro causes Twine to see element as null #474

Closed brandenon closed 6 years ago

brandenon commented 6 years ago

I had trouble implementing this W3 tutorial on creating a draggable <div> object into a project of mine earlier, so I thought I'd try it out with a blank Twine story. I pasted the HTML as-is into a passage, pasted the CSS into my Story Stylesheet, and pasted the Javascript into the Story Javascript, but was met with

Error [tw-user-script-0]: Cannot read property 'id' of null.

Placing the Javascript into a <<script>> macro underneath the HTML returned the same error. However, copying the Javascript into a <script> tag executed the code properly. I am unsure if this is a bug or not; if it is not, an explanation of the difference between the Twine <<script>> macro and HTML <script> tag's execution of Javascript would be greatly appreciated.

macOS Twine 2.2.1, Sugarcube 2.25.0

brandenon commented 6 years ago

Didn't realize there was an issue tracker for Sugarcube, my apologies. I have posted the issue there instead.