Creating Counters for dummies

Game development with Board Game Arena Studio
Post Reply
User avatar
Ilmion
Posts: 30
Joined: 28 March 2020, 03:26

Creating Counters for dummies

Post by Ilmion »

I have look in this wiki page : http://en.doc.boardgamearena.com/Counter
and in the Gomoku.js example.

First, one of those seem out dated, because neither use the same methode to make counter.
What I want is a counter like the score counter on which I can use toValue (this one animate the number changing value, which I find nice).
ie:

Code: Select all

 this.scoreCtrl[ player_id ].toValue 
For that, I think the way describe in the wiki is what I'm looking for. Am I wrong ?

But, I am missing some context. I do not know where the 'player' variable come from in this section :

Code: Select all

player.handSizeCounter = new ebg.counter();
player.handSizeCounter.create('hand_size_player_' + player_id);
it is not clear in the wiki.
User avatar
Victoria_La
Posts: 665
Joined: 28 December 2015, 20:55

Re: Creating Counters for dummies

Post by Victoria_La »

Why do you need counter? If you need to update score it is already there you just need to impement update notification, something like

Code: Select all

notif_score: function(notif) {
			// console.log(notif);
			this.scoreCtrl[notif.args.player_id].setValue(notif.args.player_score);
			this.animScore(notif.args);
		},

That will update score (starts) on miniplyer panel

The animScore function if you want to implement fancy animation (i.e. write your own), for example sliding score +3 with fadeAndDestroy over some
boad elements. If you want simple animation use toValue instead ot setValue.

The default counter barely have any animation but for that you basically have to create a <span> element in your template, i.e.

<span id="my_counter">N/A</span>

Than in js you will do

Code: Select all

player.myCounter = new ebg.counter();
player.myCounter.create('my_counter');
player.myCounter.setValue(1);
player.myCounter.toValue(100);
User avatar
Ilmion
Posts: 30
Joined: 28 March 2020, 03:26

Re: Creating Counters for dummies

Post by Ilmion »

EDIT : Did not read full post, sorry (or it was edited which is fine :D)

Yes the 'to_value' is ok for me, I got everything you said, the only part I do not get is where those the 'player' variable come from ?
The one ine 'player.myCounters' ?

I want the new counter for other resource of the players.
User avatar
Victoria_La
Posts: 665
Joined: 28 December 2015, 20:55

Re: Creating Counters for dummies

Post by Victoria_La »

I updated the Counter wiki btw.
The player_id variable comes from the loop , as you inject this per player, its is not part of example.
This is just example it could have been 'counter_'+ player_color.
I assume you need to see Gomoku code to know how its done in the loop.
User avatar
Ilmion
Posts: 30
Joined: 28 March 2020, 03:26

Re: Creating Counters for dummies

Post by Ilmion »

You are the gift that keeps on giving, your edits in the wiki are really helpfull, specially the counter creation in the loop.
So should I understand that the 'player.handSizeCounter' should have been 'this.handSizeCounter[player_id]" ?
or in the example in your previous post : 'this.myCounter' ?

Because, I still have no idea where that 'player' variable come from ? An artefact of the past ?
User avatar
Victoria_La
Posts: 665
Joined: 28 December 2015, 20:55

Re: Creating Counters for dummies

Post by Victoria_La »

There is no reference to "player" on the wiki anymore. It was probably of code of gomoku but current code does not use ebg.counter anymore.
Player was probably array to keep the data.
If you do use per player counter yes it would be this.handSizeCounter[player_id], and I added this example at the bottom of the wiki together
with injection of template html on startup
Post Reply

Return to “Developers”