Streak Points (not Reset Current Points) [solved]

Discussion in 'How Can I...?' started by JSeeger6, Apr 28, 2020.

  1. JSeeger6

    JSeeger6 Avid Boxer

    Joined:
    Aug 29, 2018
    Messages:
    100
    Likes Received:
    12
    I'm looking to make it so when the character progresses to another level the current points don't reset. This way, the current points act like a "longest-streak" and only reset to 0 when the character dies.

    Here is a download link to a BBDoc of a template based on the "Progression" template if anyone wants to give it a shot, feel free to download. Otherwise if you already know how, please let me know! Thanks!!
     
  2. JSeeger6

    JSeeger6 Avid Boxer

    Joined:
    Aug 29, 2018
    Messages:
    100
    Likes Received:
    12
  3. Sean Buildbox

    Sean Buildbox Serious Boxer

    Joined:
    Sep 24, 2015
    Messages:
    902
    Likes Received:
    1,076
    Think the issue here is you're using a "Restart" button on Level Complete UI. If that is say a button routing to the next world I believe Current Score will not reset until character death ;)
     
    Hue Buildbox likes this.
  4. JSeeger6

    JSeeger6 Avid Boxer

    Joined:
    Aug 29, 2018
    Messages:
    100
    Likes Received:
    12
    Hey @Sean Buildbox thanks so much for the reply! Unfortunately, it looks like the game doesn't proceed to the next level unless it's a "Restart" button and I can't use another world for what I'm trying to accomplish with this game. Are there any workarounds for this?

    I've already tried replacing the "Restart" with a "Default" nav button bringing it back to the same world, but that has the same function as "Restart."
     
  5. Sean Buildbox

    Sean Buildbox Serious Boxer

    Joined:
    Sep 24, 2015
    Messages:
    902
    Likes Received:
    1,076
    So the plan for your game is to constantly have the user replay one world over and over? But you do not want high score to reset until they lose? The restart button is restarting the same world. It's not going to the next level it's just replaying.

    Guess I would ask why you wouldn't just go randomized levels at that point? The set up you have in the example file would be highly unusual for production
     
  6. Sean Buildbox

    Sean Buildbox Serious Boxer

    Joined:
    Sep 24, 2015
    Messages:
    902
    Likes Received:
    1,076
    Thinking some more however in the latest update and using checkpoints correctly you could probably do what you're looking to do. Loading checkpoint instead. Again all depends on the game
     
  7. Vlad-NY

    Vlad-NY Serious Boxer

    Joined:
    Jul 21, 2018
    Messages:
    604
    Likes Received:
    360
    Well I can't follow what your intentions are but One thing that I did is to change the Amount property of that font that has "this should't reset" to Best so it wont reset every time you load a new scene.

    Here are my suggestions to fix this issue. I can't save your project because I'm using 3.2.1 and you saved it with an older version so here is what You need to do:
    1. Change your Label (DefaultLabel) from the Game UI to:
    - Name: StreakFont
    - Function: User Text
    !!! Note: The name of the font is important do not change this to anything else if you do not understand the code

    2 Open your Character object and replace the code from the Defeat node code with:
    Code:
    function init(){
        if(Settings.currentStreak == undefined){
            Settings.currentStreak = 0;
        }
        let UIText = this.ui().find('StreakFont')[0];
        let value = Settings.currentStreak;
        UIText.setText(value.toString());
    }
    
    function update(dt){
    }
    
    function signal(name, value){
        if(value){
            this.emitSignal('Defeat', true);
            let start = this.entity().component('Start');
            start.setCreated(false);
           
            Settings.currentStreak = 0;
            this.scene().setScorePoint(0);
        }
    }
    And the Level Selector node code with:
    Code:
    var _increased = false;
    function init(){
    }
    
    function update(dt){
    }
    
    function signal(name, value){
        if(name == 'Enabled'){
            if(Settings.levelID === undefined || Settings.levelID != Settings.levelID){
                Settings.levelID = 1;
            }
            this.scene().addLevel(String(Settings.levelID));
        }
        else if(name == 'Next' && !_increased){
            _increased = true;
            Settings.levelID += 1;
            let value = Settings.currentStreak;
            this.scene().setScorePoint(value);   
        }
    }
    3 Open the Point Object and replace the Add Point node code with:
    Code:
    function init(){
    }
    
    function update(dt){
    }
    
    function signal(name, value){
        if(value){
            let amount = this.attribute('Amount');
            this.scene().addScorePoint( amount );
           
            if(Settings.currentStreak == undefined){
                Settings.currentStreak = 0;
            }
           
            Settings.currentStreak += 1;
           
           
            let UIText = this.ui().find('StreakFont')[0];
            let value = Settings.currentStreak;
            UIText.setText(value.toString());
        }
    }
        
    Save the game and enjoy!
     
    JSeeger6 likes this.
  8. JSeeger6

    JSeeger6 Avid Boxer

    Joined:
    Aug 29, 2018
    Messages:
    100
    Likes Received:
    12
    The example file I provided is the exact same template that Buildbox provides actually, so I'm not sure why it would be out of the ordinary! The only thing I manually added was the text and the "Best" score to demonstrate what I'm trying to accomplish through this template.

    I am only looking to have the current points reset if the character is defeated regardless of the world or scene they are in. That way the character can keep accumulating "current points" as they progress through the scenes and the "Best" score would accurately keep track of that. This system is used in Helix Jump, Snake vs Block, and many others so I don't think it's abnormal. In the example file, the "Current Score" resets with every level progression regardless of randomization actually so randomization wouldn't fix it unfortunately. Checkpoints is a good idea though! I can give that a shot.
     
  9. JSeeger6

    JSeeger6 Avid Boxer

    Joined:
    Aug 29, 2018
    Messages:
    100
    Likes Received:
    12
    Thank you SO much Vlad. Can't tell you how much I appreciate you taking the time to do this and help. You absolutely have the right idea - I followed your instructions exactly and am getting a JS error "UIText is undefined." I am using 3.2.1 now so feel free to overwrite the save and send it over if you don't mind! I'd love to see it working. Thanks again Vlad.
     
  10. Vlad-NY

    Vlad-NY Serious Boxer

    Joined:
    Jul 21, 2018
    Messages:
    604
    Likes Received:
    360
    You skipped the step one that's why you got that JS error, there's no need to upgrade to 3.2.1
    redo this:
    1. Change your Label (DefaultLabel) from the Game UI to:
    - Name: StreakFont
    - Function: User Text

    https://ibb.co/2dkFXGM
     
    Last edited: Apr 29, 2020
    JSeeger6 likes this.
  11. Vlad-NY

    Vlad-NY Serious Boxer

    Joined:
    Jul 21, 2018
    Messages:
    604
    Likes Received:
    360
    As for your project here are the links:
    3.2.1 tempalte
    Point node
    Character node

    Please let me know if this is what are you looking for and if everything is good or not :). I will check this thread tomorrow morning
     
    Last edited: Apr 29, 2020
    JSeeger6 likes this.
  12. JSeeger6

    JSeeger6 Avid Boxer

    Joined:
    Aug 29, 2018
    Messages:
    100
    Likes Received:
    12
    I actually did change the Label but strangely it wasn't working when I did it!

    THANK YOU! Yours worked great for the new "Current Points"! Unfortunately now the "Best" score isn't reading from the new "Streakscore" but still from the "Current Points." Therefore the "Best" isn't accurately reading from the new Streakscore that you made.
     
  13. Vlad-NY

    Vlad-NY Serious Boxer

    Joined:
    Jul 21, 2018
    Messages:
    604
    Likes Received:
    360
    You have all the necessary code in front of you to achieve what you want. Just play with it, I'm to tiered to stay awake its almost 4 am now :(
     
    JSeeger6 likes this.
  14. JSeeger6

    JSeeger6 Avid Boxer

    Joined:
    Aug 29, 2018
    Messages:
    100
    Likes Received:
    12
    Got it!!! Couldn't have done it without your code Vlad, seriously thank you so much.
    I managed to actually not use the "User Text" system and found a way to add the "Settings.currentStreak" to the world's "Current Points." That way, the "Best" score keeps an accurate track of the points as the levels progress. If you'd like me to show you the code for it at any point, please let me know. Thanks again for your help!!!
     
  15. Vlad-NY

    Vlad-NY Serious Boxer

    Joined:
    Jul 21, 2018
    Messages:
    604
    Likes Received:
    360
    Well for the thing you described above you need the following 3 nodes:

    Character:
    ==== Level Selector: ====
    Code:
    var _increased = false;
    function init(){
    }
    
    function update(dt){
    }
    
    function signal(name, value){
        if(name == 'Enabled'){
            if(Settings.levelID === undefined || Settings.levelID != Settings.levelID){
                Settings.levelID = 1;
            }
            this.scene().addLevel(String(Settings.levelID));
        }
        else if(name == 'Next' && !_increased){
            _increased = true;
            Settings.levelID += 1;
            let value = Settings.currentStreak;
            this.scene().setScorePoint(value);  
        }
    }
    ==== Defeat ====
    Code:
    function init(){
        if(Settings.currentStreak == undefined){
            Settings.currentStreak = 0;
        }
        let value = Settings.currentStreak;
        this.scene().setScorePoint(value);
    }
    
    function update(dt){
    }
    
    function signal(name, value){
        if(value){
            this.emitSignal('Defeat', true);
            let start = this.entity().component('Start');
            start.setCreated(false);
          
            Settings.currentStreak = 0;
            this.scene().setScorePoint(0);  
        }
    }  
        
    And on on Point object we need to change:
    ==== Add Point ====
    Code:
    function init(){
    }
    
    function update(dt){
    }
    
    function signal(name, value){
        if(value){
            let amount = this.attribute('Amount');
          
            if(Settings.currentStreak == undefined){
                Settings.currentStreak = 0;
            }
          
            Settings.currentStreak += 1;
            let value = Settings.currentStreak;
            this.scene().addScorePoint( amount );
        }
    }
        

    Long story short:
    You can use The settings class to move a variable cross nodes and you have to use "addScorePoint( amount )" to set your current points properly. If you use this the best points will be calculated as expected.

    ps: I'm glat that I could help you and I hope you learn something out of this :)
     
    JSeeger6 likes this.
  16. Leo Medd

    Leo Medd Boxer

    Joined:
    Apr 10, 2020
    Messages:
    2
    Likes Received:
    1
    Hi Guys , I am new to this, I know zero coding ( too bad I know )
    and i posted a game in Google Play and I realized the points NEVER RESET !!
    I tried EVERYTHING but a simple solution was to put a NAVIGATION BUTTON on top of
    another one with "Function " value as " RESET SETTINGS" and "Block Touch Through"
    UNCHECKED as the pictures show .
    https://ibb.co/4Fv4SWZ
    https://ibb.co/3TN67FH
    Down side to that ? an annoying RESET MESSAGE everytime I Press that but, I changed it to
    " LETS PLAY WITH ANOTHER SHIP ! " and it doesnt look that agressive !!
    It works right now for my game !!!
     
    Vlad-NY likes this.

Share This Page