Random Number Generator As A Point Score

Discussion in 'How Can I...?' started by Dean Wilson, May 9, 2020.

  1. Dean Wilson

    Dean Wilson Boxer

    Joined:
    May 5, 2020
    Messages:
    7
    Likes Received:
    1
    Hi Guys, hoping someone can help me with my 2D game.

    I have objects on the screen and when touched I would like them to generate a random number 1-100 which will be added to their point score.

    Can I do this with nodes or will it take some scripting?
    So passing a random number into the Add Points Node.

    Thanks
    -Dean
     
  2. Dean Wilson

    Dean Wilson Boxer

    Joined:
    May 5, 2020
    Messages:
    7
    Likes Received:
    1
    I got it working. in my object, touch - add points.
    I changed my points to this and it works fine..
    Now in touch it generates a number between 1 and 1000 and adds it to my point score.

    Code:
    let callNameReset;
    let callNameAdd;
    let arg;
    let amount;
    
    function init() {
        let pc = this.attribute('Points/Coins');
        let lg = this.attribute('Local/Global');
        callNameReset = 'reset'
            + (lg == 'kLocal' ? '' : 'Global')
            + (pc == 'kCoins' ? 'Coins' : 'Points')
    
        callNameAdd = 'addScore'
            + (pc == 'kCoins' ? 'Coin' : 'Point')
    
        let ct = this.attribute('Current/Total');
        arg = (ct != 'kCurrent');
       
        //amount = this.attribute('Amount');
    }
    
    function update(dt){
    }
    
    function signal(name, value){
        if(name == 'Enabled' && value){
    
    amount = Math.random() * 1000;
                   
    this.scene()[callNameAdd](amount);
           
        }else if(name == 'Reset' && value){
            this.scene()[callNameReset](arg);
        }
    }
        
     

    Attached Files:

    Playkit likes this.
  3. Playkit

    Playkit Boxer

    Joined:
    Jan 21, 2020
    Messages:
    13
    Likes Received:
    3
    Cool great for a special reward thanks for sharing !
     
    Dean Wilson likes this.

Share This Page