Global Variables

(Greg) #1

I’ve been trying to figure out how to use “Global Variables” in Hype so that they work across all scenes. At first I was setting a global in Hype’s javascript function window with this code…

	window.theNumber = 5

Then I had to add that script to each scene via the Scene Inspector using the “On Scene Load” option. I couldn’t see how that was any different than simply setting a regular variable, such as…

	var theNumber = 5

So I tried setting the Global Variable in the HEAD HTML like this…

	<script  type="text/javascript">

	window.theNumber = 5


I’m not sure that this is the proper method, but it seems to work. So, now in each scene I can run a script like this…

var x = document.getElementsByClassName('myNumber');

for (var i = 0; i < x.length; i++)

x[i].innerHTML = theNumber

And I don’t have to call the global var script in the Scene Inspector via “On Scene Load” - YAY! (19.4 KB)

(strmiska) #2

you also can load once in the first scene of a document. the it´ll be also avaliable for all scenes.

(Andrew) #3

I tend to use this method more than storing them in elements, or window, document.