Question about Variables

(kerguelen) #1

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 ?

(Greg) #2

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

(kerguelen) #3

OK, can you be more precise ?

(Greg) #4

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.

(kerguelen) #5

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

(Greg) #6

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

(kerguelen) #7

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

(Greg) #8

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

(kerguelen) #9

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

(strmiska) #10

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)

(kerguelen) #11

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

(strmiska) #12

timer (13.1 KB)

(kerguelen) #13

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.

(strmiska) #14

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

(kerguelen) #15

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

(strmiska) #16

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

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