Page 1 of 2
Force gamedatas update
Posted: 29 March 2021, 18:10
by SquiZz
Hello dear fellow developpers,
I'm a beginner here and in game development, but I try it anyway...
I uncounter an issue with gamedatas. In fact at the beginning of the game I asked to players to choose a team and a team name. I put these in the modified data base
player, and after I want to update player's interfaces by putting these datas and to show some tables.
So I used the code in .js after changing game state :
Code: Select all
var team_name = this.gamedatas.players[ player_id ].team_name;
var team_race = this.gamedatas.players[ player_id ].race;
But one player get half of the datas and the other one none... So I understood that
gamedatas is not updated at each state...
So I used in .php in the previous
leaving state
It works but I'm not happy of that, so I tried with notifications
Code: Select all
// in .game.php
$update_gamedatas = self::getAllDatas();
self::notifyAllPlayers( "team_chosen", clienttranslate( 'All players have chosen a team' ), array( "gamedatas" => $update_gamedatas));
//in game.js
// in notification
dojo.subscribe( 'team_chosen', this, "notif_team_chosen" );
//and after
notif_team_chosen: function( notif)
{
console.log('notif_team_chosen');
console.log( notif );
this.gamedatas = notif.args.gamedatas;
}
But the brower don't like it...
What are your tips to force an gamedata update?
Thanks!
Re: Force gamedatas update
Posted: 29 March 2021, 23:23
by tchobello
hi.
sorry to ask, but what to you really want to do, display, update ?
this.gamedatas is used when creating the game or refreshing with F5.
Re: Force gamedatas update
Posted: 30 March 2021, 13:04
by Victoria_La
What is location.reload()??
To send extra data from player table you have to implement it in self::getAllDatas()
I don't see it here
Re: Force gamedatas update
Posted: 30 March 2021, 20:00
by RavingWanderer
Location reload is Javascript for forcing a reload. Not the best thing to do on BGA unless really necessary.
OP needs to propagate changes (reported either via state args or via notifications) into their gamedata, and then reflect the changes into the DOM as needed. S/he needs to make sure all parties get notified of the changes too.
Re: Force gamedatas update
Posted: 31 March 2021, 11:22
by SquiZz
Hello,
In fact I tried to use getalldata method in .php but it doesnt't update gamedatas visible by .js
So I used notification to transfert datas.
Code: Select all
$sql = "SELECT player_id id, player_name name, player_score score, team_name team_name, team_race race FROM player ";
$update_player_datas = self::getCollectionFromDb( $sql );
self::notifyAllPlayers( "team_chosen", clienttranslate( 'All players have chosen a team' ), array(
"player_datas" => $update_player_datas
));
And in .js
Code: Select all
notif_team_chosen: function( notif )
{
console.log('notif_team_chosen');
console.log( notif );
var data_update = notif.args.player_datas;
for(var player_id in data_update)
{
var team_name = data_update[ player_id ].team_name;
var team_race = data_update[ player_id ].race;
var player_name = data_update[ player_id ].name;
var update_name = team_name +' - '+ player_name +' - '+ team_race;
$('team_'+ player_id).innerHTML = update_name;
var table = team_race+'_'+player_id;
dojo.style( table, 'display', 'table');
}
}
But I get an error from js from dojo.style (enable to set null...). I don't understand why because I check
table variable and it fit with id in .tpl... Any ideas?
Re: Force gamedatas update
Posted: 31 March 2021, 12:06
by Tisaac
Are you sure you checked with right value ?
Add a console.log($(table)) in your code before the dojo.style, and see what's returned.
Re: Force gamedatas update
Posted: 11 April 2021, 17:46
by SquiZz
Hello,
I put console.log on my variable
table, but it doesn't appear in game log...
Code: Select all
notif_team_chosen: function( notif )
{
console.log('notif_team_chosen');
console.log( notif );
var data_update = notif.args.player_datas;
for(var player_id in data_update)
{
var team_name = data_update[ player_id ].team_name;
var team_race = data_update[ player_id ].race;
var player_name = data_update[ player_id ].name;
var update_name = team_name +' - '+ player_name +' - '+ team_race;
$('team_'+ player_id).innerHTML = update_name;
var table = team_race+'_'+player_id;
console.log ('table');
console.log ( table );
//dojo.style( table , 'display', 'block');
}
}
I get the log of team chosen but no trace of
table :
...
< yourturnack
{"player":"2347002"}
> wakeup.html?myturnack=true&table=264855&testuser=2347002
< gameStateChange
{"id":9,"active_player":2347002,"args":null,"type":"activeplayer","reflexion":{"total":{"2347002":"166","2347003":"169"}},"updateGameProgression":0}
< team_chosen
{"player_datas":{"2347002":{"id":"2347002","name":"SquiZz0","score":"0","team_name":"fghgh","race":"Orcs"},"2347003":{"id":"2347003","name":"SquiZz1","score":"0","team_name":"jhgj","race":"Humans"}}}
< gameStateChange
{"id":3,"active_player":"2347003","args":null,"type":"game","reflexion":{"total":{"2347002":"166","2347003":169}},"updateGameProgression":0}
...
Re: Force gamedatas update
Posted: 11 April 2021, 18:01
by SquiZz
Sorry in fact I get in browser console :
table
null
table
null
I don't get why...
Re: Force gamedatas update
Posted: 11 April 2021, 18:18
by SquiZz
OK then it was a space issue...
Code: Select all
var table = team_race +'_'+ player_id;
is correct
Code: Select all
var table = team_race+'_'+player_id;
is NOT correct...
But I still have a error form dojo.style...
Do I have to put dojo.style( table,...) or dojo.style( $(table),... In both ways I get an error
table
Orcs_2347002
During notification team_chosen
n is null
I checked html code, I have a good id available :
Code: Select all
<table id="Orcs_2347002" class="table_team" style="display: none">
Re: Force gamedatas update
Posted: 11 April 2021, 18:34
by Tisaac
SquiZz wrote: ↑11 April 2021, 18:18
OK then it was a space issue...
Code: Select all
var table = team_race +'_'+ player_id;
is correct
Code: Select all
var table = team_race+'_'+player_id;
is NOT correct...
But I still have a error form dojo.style...
Do I have to put dojo.style( table,...) or dojo.style( $(table),... In both ways I get an error
table
Orcs_2347002
During notification team_chosen
n is null
I checked html code, I have a good id available :
Code: Select all
<table id="Orcs_2347002" class="table_team" style="display: none">
What ? No. Both are correct !
What is the game name on the studio ?
Also, are you on the discord server for dev ? Live debugging is much easier than question/answer on forum