[SOLVED] player_name from

Game development with Board Game Arena Studio
Post Reply
User avatar
Rudolf
Posts: 566
Joined: 24 December 2011, 23:04

[SOLVED] player_name from

Post by Rudolf »

Hello,
Well another pb today that hurts my time:
I've got in game.php:

Code: Select all

$sql = "SELECT player_id id, player_name name, player_color color,player_colorid colorid, player_score score FROM player ";
$result['players'] = self::getCollectionFromDb( $sql );
And I try to log playername in js file:

Code: Select all

for( var player_id in gamedatas.players )
            {
                var player = gamedatas.players[player_id];
		var pname= gamedatas.players['name'];
		var colorId = player['colorid']; 
		var player_board_div = $('player_board_'+player_id);	
		console.log('!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!:'+pname);
And Console give me 'UNDEFINED' for pname.... I don't understand why... is it that the string is not well formated and seems to be null string?
If I replace by colorId, I have the colorId well displayed ('ORA' for example)...

Somebody could explain to me what's wrong, and how I can solve this... I spend to much time for this... thnaks in advance.
Last edited by Rudolf on 07 August 2015, 03:13, edited 1 time in total.
User avatar
pikiou
Posts: 389
Joined: 03 October 2011, 05:36

Re: player_name from

Post by pikiou »

gamedatas.players is already used by the framework, better use another property like gamedatas.playerList or gamedatas.playerDetails.

From the console, directly access gamedatas to see what's wrong with it: gameui.gamedatas
Yes "gameui" is the equivalent of "this". So is "g_sitecore".

Now here is what should fix your issue.

Code: Select all

var pname= gamedatas.players['name'];
should be

Code: Select all

var pname = player.name;
Your JS code kinda shows you haven't properly learnt its basics. You'll enjoy coding way more if you know what you're doing.
To do so get this book: https://github.com/jasonzhuang/tech_boo ... Script.pdf
Click on raw to download the pdf. I doubt this is legal, as the book can be bought online, so do send some money love to the author if you find it useful. I sure did.

Only chapters 2, 4a+b, 5, 7 and 8 are useful in order to dev on BGA Studio. The 5 is vital if you know other languages and think JS is pretty much the same.
dojo handles events and DOM manipulation, saving you the trouble of variations between browsers. So don't bother too much about code in chapters 7 and 8, it'll be handled by dojo.connect, dojo.disconnect, dojo.place, dojo.style...
User avatar
Rudolf
Posts: 566
Joined: 24 December 2011, 23:04

Re: player_name from

Post by Rudolf »

Thank you Pikiou.
Post Reply

Return to “Developers”