Question about Variables

I’ve seen a lot of examples here of projects using variables.
It opens great doors, for games, for example.
If my project has 10 scenes, will variables be transmitted to every scenes of the project ?
If yes, how can I make test when a scene is opened to display elements or trigger a given timeline according to variable state ?

I think you may run into problems with 'Unique Element ID’s.

OK, can you be more precise ?

Element ID's are unique, meaning you can only use an ID name once in a document. So, if you had an element named "My_Element" and tried to add another element with that same name you would get a warning in Hype. Classes might work, but I do not know if the variables are transmitted throughout the scenes in Hype.

If I pay attention and give every object a unique ID, may I be able to get rid of this problem ?

1 Like

Please give it a try, and let the forum know your results.

I’m not skilled enough with coding to be able to achieve this by myself, I’m afraid

This test seems to indicate that variables are Not transmitted between scenes. You might try researching ‘Global Variables’.

var_test.hype.zip (19.7 KB)

Hi Greg, thanks for the file. I try to understand how it works but am not really sure of it

to use variables for all scenes you´ve to use i.e - window.timer = "something"
so, if you use “window”, the variable is avaliable in the DOM. (all scenes)

Any exemple you could post to show I it would work ?
Thanks. Sorry for my terrible lack of knowledge in programming

timer
timer.hype.zip (13.1 KB)

Thanks Strmiska for the exemple.
but I don’t see the connection with the fact of passing a variable from one scene to another.
I was thinking of something like :

  • an openning scene with 10 choices (x)
  • next scenes will display content according this choice, play timeline (x) or show images connected this choice.

you can call a “window”-variable from every scene. a normal “var” not.

Oh, you mean that instead of giving a variable the name “Variable”, the name would be “window.Variable” ?

instead of
var test = hypeDocument.getElementById("test");
take
window.test = hypeDocument.getElementById("test");

then you can call either “window.test” or “test”

4 Likes

Great! now I know how to display and play with variables. Love it! :sweat_smile:

1 Like

Best practice these days is…

hypeDocument.customData.test = 'whatever';

in a more broad sense you can also just do …

hypeDocument.test = 'whatever';

… but then you would have to make sure you don’t overwrite official API.

1 Like