More Switches (buildbox 3)

Discussion in 'Buildbox General Discussion' started by HG-2018, Nov 5, 2020.

  1. HG-2018

    HG-2018 Avid Boxer

    Joined:
    Jun 18, 2018
    Messages:
    388
    Likes Received:
    220
    I try to add more switches but i dont know why it doesnt work. I hope any one can help me.


    //Node attribute variables

    let _emitOnStart = true;



    ///Internal variables

    let _switched = false;



    function init() {

    //get the node attributes

    _emitOnStart = this.attribute('Emit On Start');

    }



    function start() {

    //If Emit on start is required then we send

    // Signal A as true to start the switch on A

    if (_emitOnStart) {

    this.emitSignal('A', true);

    this.emitSignal('B', false);

    this.emitSignal('C', false);

    }

    }



    function update(dt) {



    }



    function signal(name, value) {

    //Check the incoming signals



    //Trigger the switch on when the signal is true

    if (name == 'Trigger' && value) {

    //Emit the signal opposite to current state

    if (_switched) {

    this.emitSignal('A', true);

    this.emitSignal('B', false);

    this.emitSignal('C', false);

    }

    else {

    this.emitSignal('A', false);

    this.emitSignal('B', true);

    this.emitSignal('C', false);

    }

    else {

    this.emitSignal('A', false);

    this.emitSignal('B', false);

    this.emitSignal('C', true);

    }

    //Update the switch state

    _switched = !_switched;

    }

    }
     

Share This Page