New High Score Node Free

Discussion in 'BBNodes' started by chris15smile, Sep 29, 2020.

  1. chris15smile

    chris15smile Boxer

    Joined:
    Apr 30, 2016
    Messages:
    17
    Likes Received:
    2
    Hey everyone

    This is my first one of these, I wanted to share as I couldn't find anything regarding a trigger for when a new high score was achieved.


    Placing of Asset:
    There are 2 script nodes that work together, so have released as an asset.
    Place the asset in your Game Over UI.

    How It Works:
    Upon loading up your Game Over UI, the Script Node retrieves the current score, and it then loads the last scenes high score.

    The High Score node retrieves the latest high score and saves after slight delay to allow for the first script to retrieve the previous high score.

    It is currently set to the points system, I haven't tried with coins, but assume it should work with a few tweaks: (I would start with the following)
    1 In the Script Node, change .currentPoints(); to .currentCoins();
    2 In the High Score Node, change .bestPoints(); to .bestCoins();

    I'm not a coder, so this took me a while, I'm looking forward to utilizing it, and I hope it doesn't have any issues.

    Feel free to improve :) and comment any adjustments and changes :)
    This is also my first post, hopefully you find the attached zip file.

    Hey everyone, the Asset was update 2/10/2020 17:00
    Kind Regards


    Observer nodes.png High score.png
    Game over UI.png
     

    Attached Files:

    Last edited: Oct 2, 2020
  2. chris15smile

    chris15smile Boxer

    Joined:
    Apr 30, 2016
    Messages:
    17
    Likes Received:
    2
    New high Score Script node is the below: this has been updated in the zip file in previous post

    let variableName;
    let high

    function init() {
    variableName = this.attribute('Variable Name');}

    function start(){}

    function update(dt){}

    function signal(name, value, sender){
    //let points = this.scene().currentPoints();
    let high = Settings[variableName];

    if (name == 'Enabled') {
    if (high === undefined){
    high = 0};

    if ((this.scene().currentPoints()) > high){
    this.emitSignal("Winning", true);}}}

    function requested(name, arg, sender){
    return this;
    }







    High Score Script Node

    let points

    function init(){}

    function start(){}

    function update(dt){}

    function signal(name, value) {

    if (name == 'Enabled' && value && this.scene()) {
    let points = this.scene().bestPoints();
    this.emitSignal('Value', points);
    }
    }

    function requested(name, arg, sender){
    return this;
    }
     
  3. Bluemusic

    Bluemusic Boxer

    Joined:
    Apr 7, 2020
    Messages:
    59
    Likes Received:
    10
    Hi and thanks for sharing!
    I´ve downloaded the asset and put it in the Game Over UI. Anything else I need to do?
    I understand that this could be used to trigger something but can´t get it to work.
    Would love to trigger a label in the game saying "highscore".
     
  4. chris15smile

    chris15smile Boxer

    Joined:
    Apr 30, 2016
    Messages:
    17
    Likes Received:
    2
    Hey,
    Awesome, let's get this working for you :)

    Just to confirm that you are using points and not coins, otherwise we can change it for coins.

    So you will need to add a Receive node to what you would like to Trigger

    And put in the Event Group and Event name the same that is in the Send Node, You can change these to what you would like but just make sure they match.

    upload_2020-12-1_8-59-17.png

    There are different ways to do things with Buildbox, and depending on where you want your highscore label to pop up will depend on what we do next.

    Do you want the Label to pop up in the UI? or in the world?

    Also you can add a logger node to the end of any of these node to see the value coming form them to help determine where something might not be going right :)

    If you haven't used a logger node before, connect as many as you want to each node or try one at a time to not make it too confusing.
    Label the logger by changing the log name, don't mix this up with changing the loggers name, but changing the LOG NAME.
    When you use the Buildbox preview window to test your game, there is a button at the top to select view logs.

    Check out my game and see it working,
    Heads up, it's a hard game
    Android: https://play.google.com/store/apps/details?id=com.appiiigos.pivoty
    IOS: https://apps.apple.com/us/app/pivoty/id1531663324

    Happy to help :)
     
  5. Bluemusic

    Bluemusic Boxer

    Joined:
    Apr 7, 2020
    Messages:
    59
    Likes Received:
    10
    Hi.
    Thanks for explaining:) That said, I know Buildbox quite well and use receive all the time. I´ve put the highscore observer in the Game Over UI and that works fine. Thanks!

    My wish was to get the label with highscore to pop up on screen UI.
    I´ve tried adding the same label there but it seems like its not reacting throught the game and telling the player that he has passed his highscore. So basically I want it to pop up during gameplay and not necessary afterwords:)
     
  6. chris15smile

    chris15smile Boxer

    Joined:
    Apr 30, 2016
    Messages:
    17
    Likes Received:
    2
    Hi,

    Yes that makes perfect sense, as the high score observer is in the game over UI, it is only activated once game over UI is loaded.
    So it would be required to be placed in the Game world UI, but it wont work as it is set to only run the code once on loading.

    Will need to change the code to become a listener, or to update with every frame.
    I will post update soon :)
     
  7. chris15smile

    chris15smile Boxer

    Joined:
    Apr 30, 2016
    Messages:
    17
    Likes Received:
    2
    Hey,
    I hope this is what you were after.

    Ok, so this is a different version
    High score Observer for Game World UI (triggers as soon as player hits a new high score)
    see previous posts for High Score Observer in Game Over UI (triggered at game over UI if player has passed previous high score)

    Please be mindful for this to work it is an extra bit of code running all the time as it is watching the current score and updating every frame, as soon as the event occurs it will switch off.

    I have the Receive Node ready to be added to your Label or Event.
    upload_2020-12-8_12-36-4.png

    Changes made:

    -Delay Node removed as the high score is required to be saved on initiation

    -Signal Threshold Added to prevent any extra event triggers

    -Switch was added to turn off Observer after event is triggered

    -New High Score Node Script was also changed to the below:

    //by Chris McFarlane (APPIIIGOS) https://www.appiiigos.com

    let enabled = false;
    let variableName;
    let high

    function init() {
    variableName = this.attribute('Variable Name');
    }

    function start(){
    }

    function update(dt){
    if (!enabled) return;
    let high = Settings[variableName];

    if (high === undefined){
    high = 0};

    if ((this.scene().currentPoints()) == (high+1)){
    this.emitSignal("Winning", true);
    }
    }

    function signal(name, value, sender){
    if (name == 'Enabled') {
    enabled = Math.abs(value) == 1;
    direction = value;
    //let points = this.scene().currentPoints();
    }
    }

    function requested(name, arg, sender){
    return this;
    }
     

    Attached Files:

    Bluemusic likes this.
  8. Bluemusic

    Bluemusic Boxer

    Joined:
    Apr 7, 2020
    Messages:
    59
    Likes Received:
    10
    Hi Chris
    Thanks for the effort!
    I´ve added the new UI nodes and attached an animation (png) to the receive and it works:)!
    Thanks a lot man! This is great:)

    I have some other issues. Is it okay if I send you private message on this?
     
  9. chris15smile

    chris15smile Boxer

    Joined:
    Apr 30, 2016
    Messages:
    17
    Likes Received:
    2
    No Problem

    Yeah send me a message also you can add me on Discord
    https://discordapp.com/users/441330787581952002/

    Happy to help
     

Share This Page