with a little help from Mark Hunte I got a part to work. But now I need it to be possible to change the outcome when a different button is clicked. I tried the switch statement, but obviously I am doing something wrong. So what I want to happen: if you click btn choose1, text color must be red green blue.
When you click btn choose2 text color must be yellow brown white.
Any help appreciated.MarkExampleButtonIDSToVariableName-2.hype.zip (24.4 KB)
I declared the arrays as global variables in a new on scene load js. “init()”
You should read MDN Switch about switches and how they work. Yours was completely wrong in it’s setup.
In ours once we switch to the right case, we only need to determine which colours or names we are going to use and set the global array variables accordingly.
When the second set of buttons ( name, color) calls their script; that script will be able to read those global array variables. So we do not need to do anything there with them apart from tell the textfields to use them.
0 = 1
And so on.
So in the line.
hypeDocument.getElementById("text1").innerHTML = eval([buttonID]) ;
we are saying:
get the element named “text1”, and set it’s innerHTML to: item 1 of some array.
The item number is determined by the very last .
eval([buttonID]) is just turning a string into a variable . And we have to use the  on the end of “buttonID]” or we will get the name of the array instead of to its items. I think this is only because we are using eval(). But someone with better knowledge may be able to clarify but suffice to say I am only pointing out as an anomaly to my explanation of indexes.
Thanks Mark, that’s a great explanation. I’m new to using arrays and I appreciate any help I can get.
Thank you very much Mark, I studied your switch statement and I think I know what I did wrong. The window.thing is also very important. I see that now.
But why do you use the ‘console.log()’? It seems it has no use.
The console.log() should have been commented out.
But what I use it for is debugging.
Search google for it to get a fuller explanation.
But we can print out data that is within its ()