Toggle switches

(Petr) #1

Hi there,

I am working on an interactive schematic where there are multiple switches. With each unique combination of the switches the schematic will be different (different scene). I have 0 experience with JavaScript, could anyone point me into the right direction or tell me how the code should look like?

Thank you,



This is perhaps what the code could look like

Joking aside. Do you have something you’ve started? Maybe an idea or at least the mechanics of the doc and someone may be able to help more. There are lots of “variables” that would/could change the solution to your problem so this is only an exercise to speed things up. If the document is too big then perhaps reduce it down to what it is you are focusing on. i.e 1 or 2 scenes as an example.

The biggest tip I can give you as a beginner is to write the logic out. I mean:

// A place to store the combination of "switches"
// A place to store the switch that has been "pressed"
//  show scene based on combination
  // If combination is ... then showSceneNamed("...")
// etc...

This way you can merely go through the steps and fill in the code

if(typeof switches === "undefined"){
    switches = {};
switches[] = true; // example. switch1 as an id
	console.log("Switch to Scene because switch1 is true");

This code can then be run on an action of the switch elements. Each “element” having a corresponding ID you can store.

This is the idea. But, this won’t be exactly what you need because we can’t see your logic / setup. :wink: