Page 1 of 1
Auto score on setup
Posted: 13 July 2020, 14:35
by Tisaac
Hi,
I was thinking that the score counter would automatically take the value in gamedatas.players[id].player_score on setup but this is not working.
How are we supposed to setup the scores then ?
I tried using scoreCtrl but these are not working in the the setup function, I have to wait to enter some state to make them work...
And using a notification seems a little bit too much...
Re: Auto score on setup
Posted: 13 July 2020, 14:51
by RicardoRix
Adjust player_score in the players table in the setupNewGame()
self::DbQuery( "UPDATE player SET player_score = $money");
Re: Auto score on setup
Posted: 13 July 2020, 14:59
by Tisaac
Already done but it is not showing up...
The only solution I have found so far is calling a function at each enteringState to make sure scores are consistent...
Code: Select all
updateScore: function(){
for(var pId in this.gamedatas.players){
this.scoreCtrl[pId].toValue( this.gamedatas.players[pId].player_score);
}
}
Re: Auto score on setup
Posted: 13 July 2020, 15:15
by RicardoRix
it works for me. I think you're missing something.
It's done automatically, because the same as a F5, there is nothing required JS client side to update the controls. It's only if you need to adjust the scores with a notification do you need to do the JS stuff.
Re: Auto score on setup
Posted: 13 July 2020, 15:21
by Tisaac
Can you show me an allDatas example that works ?
Maybe the field name is important.
Re: Auto score on setup
Posted: 13 July 2020, 15:24
by RicardoRix
I already did ^^
self::DbQuery( "UPDATE player SET player_score = $money");
If you go to the database and look at the player table, what does it say?
Re: Auto score on setup
Posted: 13 July 2020, 15:33
by Tisaac
No, I meant an example of getAllDatas.
The field player_score is working, the end of game is also working, it's really just the UI that won't get the proper field.
I am overwriting the default "player" key of gamedatas, so perhaps the naming of the field inside it is wrong (I am using player_score where maybe the BGA framework is using juste "score" by default ?)
Re: Auto score on setup
Posted: 13 July 2020, 15:45
by RicardoRix
just the default code:
$sql = "SELECT player_id id, player_score score FROM player ";
$result['players'] = self::getCollectionFromDb( $sql );
so its just 'score' client side.
Why would you overwrite that? I can't see any possible benefit from doing that, plus like now having problems like this.
Re: Auto score on setup
Posted: 13 July 2020, 16:02
by Tisaac
RicardoRix wrote: ↑13 July 2020, 15:45
just the default code:
$sql = "SELECT player_id id, player_score score FROM player ";
$result['players'] = self::getCollectionFromDb( $sql );
so its just 'score' client side.
Why would you overwrite that? I can't see any possible benefit from doing that, plus like now having problems like this.
Ok i will try with score.
On this game, I am actually finishing someone else's project so this was already written.
On other project, I usually avoid sending collection on the js side because it can no longer being iterated over using js array functions (which are the best)