How Can I Limit My Points (coins) ?

Discussion in 'How Can I...?' started by HarikaYesim, Jan 15, 2020.

  1. HarikaYesim

    HarikaYesim Boxer

    Joined:
    Jan 14, 2020
    Messages:
    16
    Likes Received:
    0
    In the articles , I can see how I can make scoring in my game but I couldn't find how to limit the scores (limiting points that character gains).



    My game is based on points that my character gains but I want to limit those points and if he gains more than this amount , I'm trying to make game over.
     
  2. Smart Penguins

    Smart Penguins Boxer

    Joined:
    Jan 2, 2020
    Messages:
    58
    Likes Received:
    57
    I don't think there is a way you can do that without writing some code.
    Here is some code that should do the trick.
    1) Replace your Add Point Code with this one
    2) Add number Attribute name it "Limit"
    3) Add an output signal name it "Limit Reached"

    Screen Shot 2020-01-15 at 7.19.25 AM.png

    Code:
    let callNameReset;
    let callNameAdd;
    let arg;
    let amount;
    
    //-----New Code------
    let limit;
    let callNameGet;
    //-------------------
    
    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');
       
       
        //-------New Code--------
        limit = this.attribute('Limit');
        callNameGet = 'current'
            + (pc == 'kCoins' ? 'Coins' : 'Points')
        //-----------------------
    }
    
    function update(dt){
    }
    
    function signal(name, value){
        if(name == 'Enabled' && value){
            this.scene()[callNameAdd](amount);
           
            //-----New Code------
            if(this.scene()[callNameGet]()>=limit){
                this.emitSignal('Limit Reached', true);
            }
            //-------------------
           
        }else if(name == 'Reset' && value){
            this.scene()[callNameReset](arg);
        }
    }

    -----------------------------------------------
    Our Youtube Tutorials
     
    Antone Samy likes this.
  3. HarikaYesim

    HarikaYesim Boxer

    Joined:
    Jan 14, 2020
    Messages:
    16
    Likes Received:
    0
    Thanks a lot for this . Much appreciated. limiting issue.JPG

    Although I tried the steps you stated above, I couldn't make it. Still collects them in the amount I want but doesn't game over in the defined limited amount . The thing is if I choose only points (in add point node) my character gains them . When I choose coins it didn't work even .

    Besides that I checked my project settings and I made my score type points collected (I tried different variations with coins too however it didn't work).

    I attached a screenshot what I've done.
     
  4. Smart Penguins

    Smart Penguins Boxer

    Joined:
    Jan 2, 2020
    Messages:
    58
    Likes Received:
    57
    You missed step 2, you have no "Limit" Attribute

    2) Add number Attribute name it "Limit"
    Click Add Attribute in the bottom right corner
     
  5. HarikaYesim

    HarikaYesim Boxer

    Joined:
    Jan 14, 2020
    Messages:
    16
    Likes Received:
    0
    I already did actually. Please check my screenshot above. limiting issue 2.JPG
     
  6. Smart Penguins

    Smart Penguins Boxer

    Joined:
    Jan 2, 2020
    Messages:
    58
    Likes Received:
    57
    Oh, you did. I was looking at the bottom of the list and didn't see it sorry.
    You have a Game Over listener in your Game UI and it's connected to Game Over UI, right?
    You can also try to put a Delay node before Remove because it might be deleting the entity before Defeat and Event have time to run, I was able to run without the Delay but that might be an issue.
     
  7. HarikaYesim

    HarikaYesim Boxer

    Joined:
    Jan 14, 2020
    Messages:
    16
    Likes Received:
    0
    yes, I have Game Over in my Game UI and it's connected to Game Over UI .

    I did that too but unfortunately it doesn't work.

    Thanks :) delay.JPG
     
  8. Hanomax

    Hanomax Avid Boxer

    Joined:
    Aug 24, 2018
    Messages:
    156
    Likes Received:
    84
    You can try connecting delay and remove node with defeat node. That way, it is sure, defeat code finishes processing, before entity is removed.
     
  9. HarikaYesim

    HarikaYesim Boxer

    Joined:
    Jan 14, 2020
    Messages:
    16
    Likes Received:
    0
    I tried it and it stll doesn't work .
     

    Attached Files:

    • x.JPG
      x.JPG
      File size:
      57.8 KB
      Views:
      2
  10. Smart Penguins

    Smart Penguins Boxer

    Joined:
    Jan 2, 2020
    Messages:
    58
    Likes Received:
    57
    Here, try this asset, it's from 3D Demo template, I modified the point to have the limit, you can place them in your scene and see if that works, I'm not sure why you having problems. Trying to be as helpful as I can.
     

    Attached Files:

  11. Smart Penguins

    Smart Penguins Boxer

    Joined:
    Jan 2, 2020
    Messages:
    58
    Likes Received:
    57
    Just thought of a nocode solution to this problem, just sharing it.
    Use the "Global Counter" node.
    Sometime a simple solution comes later.
    Screen Shot 2020-01-22 at 7.11.18 AM.png
     
    HarikaYesim likes this.
  12. HarikaYesim

    HarikaYesim Boxer

    Joined:
    Jan 14, 2020
    Messages:
    16
    Likes Received:
    0
    It really works , thank you very much :)
     

Share This Page