Progression Script

Discussion in 'How Can I...?' started by godofnet, Jul 4, 2020.

  1. godofnet

    godofnet Boxer

    Joined:
    Jun 10, 2020
    Messages:
    17
    Likes Received:
    1
    Hello,

    Any idea how can I customize the progression template to always show the scene number, cause when I add level select menu it will always show me the last number reached?

    Code:
    var _startLabel;
    var _endLabel;
    var _bar;
    
    var _enabled = false;
    var _distance = 1;
    
    function init(){
    
    }
    
    function update(dt){
    if(!_bar) return;
        let path = this.scene().path();
        let pathPos = path.pathPosition();
        let value = pathPos/_distance;
        if(value > 1){
            value = 1;
        }
        _bar.setPosition(-(1-value)*2.88,0,0);
        _bar.setScale(value,1,1);
       
    }
    
    function signal(name, value){
    if(value){
    _enabled = true;
    
    _startLabel = this.entity().component('StartLabel');
        _startLabel.setText(String(Settings.levelID));
            _endLabel = this.entity().component('EndLabel');
            _endLabel.setText(String(Settings.levelID+1));
       
            _bar = this.animation('Bar');
       
            _distance = this.attribute('Distance');
            if(_distance == 0){
                _distance = 1;
            }
        }
    }
     
  2. Codifie

    Codifie Avid Boxer

    Joined:
    Apr 17, 2018
    Messages:
    364
    Likes Received:
    190

    You need to add this code directly after the function init.

    Code:
    function start(){
    let label = this.entity().component('LevelLabel');
    log("Level:"+Settings.levelID);
    
    if(Settings.levelID == undefined){
    Settings.levelID = 1;
    }
    // Added below else statement for first time
    // run so "undefined" is not shown, instead
    // nothing is shown.
    else {
    
            label.setText('LEVEL '+String(Settings.levelID));
        }
    
    }
    Now you need to go into the Progression node and duplicate StartLabel, name the duplicate LevelLabel, make your font, color, size, and placement changes within the LevelLabel. Also, LevelLabel needs connected to Start.

    This should give you want you're looking for I think.
     
  3. godofnet

    godofnet Boxer

    Joined:
    Jun 10, 2020
    Messages:
    17
    Likes Received:
    1
    Thank you, I followed your instruction and still the same issue, the first time I open the game and select any level it shows "level 1".
    Let's say I passed the level and now the number is increasing so I am in "level 2" if now I go back to select the first level, it shows "level 2" instead of "level 1".
    I hope it's clear my English,
    Kindly note; am using the ready template named "Progression" and in the progression node, I disconnected the EndLabel in order to show only the level number.

    Thanks
     
  4. Codifie

    Codifie Avid Boxer

    Joined:
    Apr 17, 2018
    Messages:
    364
    Likes Received:
    190
    Oh, ok. I understand what you need. Sorry, misunderstood.
    Is your progression node in the game UI or in the world itself?
    Are you testing this on a real device or in BB preview? You need to test on real device.
     
  5. godofnet

    godofnet Boxer

    Joined:
    Jun 10, 2020
    Messages:
    17
    Likes Received:
    1
    The progression node is in the world and am testing in BB preview! should I try it on a real device?
     
  6. Codifie

    Codifie Avid Boxer

    Joined:
    Apr 17, 2018
    Messages:
    364
    Likes Received:
    190
    If you are choosing levels to start the game using the BB preview you will always start at 1. You have to test it using a real device. The only test the progression can do using BB preview is sequential test, triggered end of level test, but if you randomly choose a level to start the game with then it will always display Level 1.
     
  7. godofnet

    godofnet Boxer

    Joined:
    Jun 10, 2020
    Messages:
    17
    Likes Received:
    1
    I tried now in real device and same issue! is there any other solution maybe send node and receive node?
     
  8. Codifie

    Codifie Avid Boxer

    Joined:
    Apr 17, 2018
    Messages:
    364
    Likes Received:
    190
    Send your .bbdoc file to support. Without seeing how you have things setup it is difficult for me to help further. Describe your issue and they will take a look.

    I’m asking you to do this because I helped someone else just weeks ago who was using the Free version and the progression/level system was not cooperating at all and the support team is currently looking at his .bbdoc.
     
  9. Vlad-NY

    Vlad-NY Serious Boxer

    Joined:
    Jul 21, 2018
    Messages:
    604
    Likes Received:
    360
    The reason for why this is happening can be found in Character -> Level Selector node.

    On signal enable you can see the following code

    Code:
    if(name == 'Enabled'){
            if(Settings.levelID === undefined || Settings.levelID != Settings.levelID){
                Settings.levelID = 1;
            }
            this.scene().addLevel(String(Settings.levelID));
        }
    What this does is setting the Settings.LevelID to 1 if it is undefined or if the 2nd condition is not met

    below this you have
    Code:
        else if(name == 'Next' && !_increased){
            _increased = true;
            Settings.levelID += 1;       
        }
    This is responsible for incrementing the the level every time you hit a specific object that is set in if collide node that is linked to Next input of the same node.

    The Progression object / entity has the "Script" node that has the signal code that set's the _startLabel and _endLabel label with the values that I previously mentioned:
    Code:
    function signal(name, value){
        if(value){
            _enabled = true;
       
            _startLabel = this.entity().component('StartLabel');
            _startLabel.setText(String(Settings.levelID));
            _endLabel = this.entity().component('EndLabel');
            _endLabel.setText(String(Settings.levelID+1));
       
            _bar = this.animation('Bar');
       
            _distance = this.attribute('Distance');
            if(_distance == 0){
                _distance = 1;
            }
        }
    }
    Now please tell me again what do you want to achieve since what you are asking does not match the template so for sure you've changed something or you did not explain it very well
     
  10. godofnet

    godofnet Boxer

    Joined:
    Jun 10, 2020
    Messages:
    17
    Likes Received:
    1
    Sure! should I send the .bbdoc here or email?
     
  11. godofnet

    godofnet Boxer

    Joined:
    Jun 10, 2020
    Messages:
    17
    Likes Received:
    1

    Thank you Vlad, for sure I didn't mess with code(am so basic in coding) but maybe I didn't well explained, let me try it again, I selected the progression template from the home interface, I started by editing the progression object so first disconnect the endLabel node, Bg node and Bar node(now i have startLabel node, delay node and script node) , now back to mind map and add a new UI screen and add inside the unlock buttons for each level scene(alongside with unlock logic), now everything work fine only the number startLabel is always increasing, so lets say i reached the 3rd level then back to level select and hit 1st level button: now the number shown is 3.

    I hope i explained well with my bad English lol,
     
  12. godofnet

    godofnet Boxer

    Joined:
    Jun 10, 2020
    Messages:
    17
    Likes Received:
    1
  13. Vlad-NY

    Vlad-NY Serious Boxer

    Joined:
    Jul 21, 2018
    Messages:
    604
    Likes Received:
    360
    Hey there,

    Thanks for replying, I don't need the template since now, I think I understand what you want for that do the following steps:

    On the Progression object / entity has the "Script" node that has the signal code that set's the _startLabel and _endLabel label with the values that I previously mentioned:
    Code:
    function signal(name, value){
        if(value){
            _enabled = true;
      
            _startLabel = this.entity().component('StartLabel');
            _startLabel.setText(String(Settings.levelID));
            _endLabel = this.entity().component('EndLabel');
            _endLabel.setText(String(Settings.levelID+1));
      
            _bar = this.animation('Bar');
      
            _distance = this.attribute('Distance');
            if(_distance == 0){
                _distance = 1;
            }
        }
    }
    Since you are using only the StartLabel then that's the palce where we want to make our change. What you are looking for is for the actual scene name that can be found by using this.scene().currentLevelName() (documentation is here https://www.buildbox.com/help/buildbox-3-api-reference/scene/#currentlevelname)

    So just change the above code with this and you should be ok

    Code:
    function signal(name, value){
        if(value){
            _enabled = true;
      
            _startLabel = this.entity().component('StartLabel');
            _startLabel.setText(this.scene().currentLevelName());
            _endLabel = this.entity().component('EndLabel');
            _endLabel.setText(String(Settings.levelID+1));
      
            _bar = this.animation('Bar');
      
            _distance = this.attribute('Distance');
            if(_distance == 0){
                _distance = 1;
            }
        }
    }
    If you want to have something like "World 1, World 2 etc" or "Scene 1, Scene 2" use this code
    _startLabel.setText("World " + this.scene().currentLevelName());

    Have a good day and stay safe!
     
    Sean Buildbox likes this.
  14. godofnet

    godofnet Boxer

    Joined:
    Jun 10, 2020
    Messages:
    17
    Likes Received:
    1
    Thank you so much Vlad, now it works :):D
     
    Vlad-NY likes this.
  15. Vlad-NY

    Vlad-NY Serious Boxer

    Joined:
    Jul 21, 2018
    Messages:
    604
    Likes Received:
    360
    You're welcome! :)
     
  16. godofnet

    godofnet Boxer

    Joined:
    Jun 10, 2020
    Messages:
    17
    Likes Received:
    1

Share This Page