How To Program Setting Class

Discussion in 'Buildbox General Discussion' started by Elite Games, Dec 22, 2019.

  1. Elite Games

    Elite Games Avid Boxer

    Joined:
    Dec 18, 2019
    Messages:
    184
    Likes Received:
    84
    Hello How to program setting class and what type of information we can store in setting class.

    Can we store vector 3 , bools , Strings int ?
    How to store these ?
     
  2. Hanomax

    Hanomax Avid Boxer

    Joined:
    Aug 24, 2018
    Messages:
    157
    Likes Received:
    85
    I give you an example, how I saved haptics feedback settings into settings class.
    This is code for on/off button:
    Code:
    function init(){
        if(Settings.haptic == undefined){
            Settings.haptic = 1;
            }
        if(Settings.switched == undefined){
            Settings.switched = false;
            }
    
    }
    
    function start(){
        if (Settings.haptic == 0) {
            this.emitSignal('off', true);
            this.emitSignal('on', false);
            }
            else {
                this.emitSignal('off', false);
                this.emitSignal('on', true);
                }
    
    }
    
    function update(dt){
    
    }
    
    function signal(name, value) {
        if (name =='Trigger' && value) {
            if (Settings.switched == false && Settings.haptic == 1) {
                Settings.haptic = 0;
                this.emitSignal('off', true);
                this.emitSignal('on', false);
                }
                else {
                    Settings.haptic = 1;
                    this.emitSignal('off', false);
                    this.emitSignal('on', true);
                    }
                    Settings.switched = !Settings.switched;
                   
        }
    
    }
    And to call this Settings.haptic value in add point node, I used this code:
    Code:
    function init(){
    }
    
    function update(dt){
    }
    
    function signal(name, value){
        if(value){
            let amount = this.attribute('Amount');
            this.scene().addScorePoint( amount );
            if (Settings.haptic==1) {
                System.sendHapticFeedback(2);
                }
        }
    }
     
    Elite Games likes this.
  3. Elite Games

    Elite Games Avid Boxer

    Joined:
    Dec 18, 2019
    Messages:
    184
    Likes Received:
    84
    Thank u soo much i got it now.
     

Share This Page