Global Counter Scripting Help.

Discussion in 'How Can I...?' started by Snozzberry, Aug 8, 2019.

  1. Snozzberry

    Snozzberry Avid Boxer

    Joined:
    Apr 9, 2019
    Messages:
    103
    Likes Received:
    62
    I say help but I am pretty clueless and I am just getting familiar with reading JS.

    Scenario: I have three small platforms in my game that move together left to right to avoid obstacles. I've made it so when I get "X" amount of points it sends a signal to one of my platform objects which is connected to a "set color" note. I would like for when the points exceed "X" amount and they hit the next target number it will send the true statement to the designated "signal?" output so I can change the color of the second platform and then when next target number is reached the third platform will change color.

    I have only added the outputs that I wanted on the node and the attributes that I would like to have as well. I have been looking at other nodes with multiple outputs but I cannot wrap my head around how to do it correctly. I imagine that there will need to be an "else" statement in there along with some "< or >" operators.

    I also tried running it with 3 separate Global counters with 3 different values but it did not work. Any help or suggestions would be greatly appreciated. Thank you.

    [​IMG]

    Original Global Counter Code
    Code:
    function init(){
        this.emitSignal('Trigger', false);
    }
    
    function update(dt){
    
    }
    
    function signal(name, value){
       
        if(value){
            let id = this.attribute('Identification');
            if(Settings[id] === undefined){
                Settings[id] = 0;
            }
            log(Settings[id]);
            Settings[id] += 1;
            if(Settings[id] >= this.attribute('Target')){
                Settings[id] = 0;
                this.emitSignal('Trigger', true);
            }
        }
    }
        
     
  2. Tumbleweeds

    Tumbleweeds Boxer

    Joined:
    Dec 18, 2018
    Messages:
    20
    Likes Received:
    9
    if(Settings[id]=== this.attribute('Target')){
    this.emitSignal('Trigger', true);
    }
    if(Settings[id]=== this.attribute('Target 2')){
    this.emitSignal('Trigger 2', true);
    }
    if(Settings[id]=== this.attribute('Target 3')){
    this.emitSignal('Trigger 3', true);
    }
     
  3. Tumbleweeds

    Tumbleweeds Boxer

    Joined:
    Dec 18, 2018
    Messages:
    20
    Likes Received:
    9
    Woops. You should probably use == instead of ===
     
  4. Snozzberry

    Snozzberry Avid Boxer

    Joined:
    Apr 9, 2019
    Messages:
    103
    Likes Received:
    62
    Can’t wait to give this s try tomorrow! THANK YOU
     
  5. Snozzberry

    Snozzberry Avid Boxer

    Joined:
    Apr 9, 2019
    Messages:
    103
    Likes Received:
    62
    Worked perfectly! This will be so useful!

    I probably look like a overly grateful weirdo on this forum but I really appreciate the help! You guys are my manual. I'm learning every day.
     

Share This Page