Scoring system

How do I add the scores and make them display on level complete UI?

Hi churiboii,

I don’t have a link to your project but let me ask the following. The numbers below each item, are they updated during game play or is this just a static screen with hard coded text? If they are actual numbers stored in your game you can use something like this.

this.targetHitText.element.text = backpackUpdateEvent.amount;

You have to have a pointer to the text entity on your UI screen.

targetHitText is a text entity that I created and placed on my UI screen. Default is 0. When a defined event occurs the amount is updated on the UI screen.

In your case I would update the totals as you go during the game. The user will not see the Total until you reach this screen. To do this make sure your initial value for Total = 0; During game play you can use an event to increase your total by whatever amount by using Total += 1 or whatever the base value is of your item. Hope this helps.

2 Likes

Can I ask where to insert that code? sorry Im a beginner, thank you

https://playcanvas.com/project/961837/overview/chuck-quacker
currently testing it on scene “level 2”

1 Like

Hi churiboii,

I forked your project. Great job if this is your first experience doing this kind of development. I have the following suggestion.

var GameManagerScore = pc.createScript('gameManagerScore');

GameManagerScore.attributes.add('fScore', {type: 'entity'});
GameManagerScore.attributes.add('cText', {type: 'entity'});
GameManagerScore.attributes.add('duText', {type: 'entity'});
GameManagerScore.attributes.add('doText', {type: 'entity'});
GameManagerScore.attributes.add('qText', {type: 'entity'});

var fCount = 0;

// initialize code called once per entity
GameManagerScore.prototype.initialize = function() {

    fCount =//Do Addition of each attribute value
    this.fScore.element.text = fCount;

};
// update code called every frame
GameManagerScore.prototype.update = function(dt) {

};

You should drag and drop these values into your gameManagerScore.js attributes just like you did for gameManager. This way you will have all of the items values to add up when the game completes. Also, remember to clear fCount when the user chooses to restart.

This was a very quick way of doing this in my mind but I have not tested it. There may be a better method but this is what I could up with. Keep up the good work and let me know when you publish.

What do I put here? Im sorry if this is a basic question :frowning:

Do i make use of these?

Player.prototype.addPoint = function(points){
    //gets current text display of text element "cText", converts to integer and adds 1
    points = parseInt(this.app.root.findByName('cText').element.text) + 10;

    //updates current text display of text element "cText" to a new point count
    this.app.root.findByName('cText').element.text = points + "";

};

Player.prototype.addPoint2 = function(points2){
    //gets current text display of text element "doText", converts to integer and adds 1
    points2 = parseInt(this.app.root.findByName('doText').element.text) + 10;

    //updates current text display of text element "doText" to a new point count
    this.app.root.findByName('doText').element.text = points2 + "";
};

Player.prototype.addPoint3 = function(points3){
    //gets current text display of text element "duText", converts to integer and adds 1
    points3 = parseInt(this.app.root.findByName('duText').element.text) + 10;

    //updates current text display of text element "duText" to a new point count
    this.app.root.findByName('duText').element.text = points3 + "";
};

Player.prototype.addPoint4 = function(points4){
    //gets current text display of text element "qText", converts to integer and adds 1
    points4 = parseInt(this.app.root.findByName('qText').element.text) + 25;

    //updates current text display of text element "qText" to a new point count
    this.app.root.findByName('qText').element.text = points4 + "";
};

or the one on my gameManagerScore.js???

I will give you a quick answer but I am not in a position currently to completely have a solid answer.

fCount += parseInt(this.app.root.findByName(‘cText’).element.text);
fCount += parseInt(this.app.root.findByName(‘doText’).element.text);
.
.

Make sure that you load attributes accordingly

image

Sorry for the quick answer. I can have a better look later this evening.

It worked fine!!! Thank you so much!!!

Great! I think there is a much more elegant way to do this but it’s what I came up with quickly. Usually I do a bit of testing. I wish you well with your game. Looks great.