Page 1 of 1
adding stuff to player panel - cannot get it error free
Posted: 03 July 2021, 01:16
by developgame
Hi Everyone:
I like to add two containers ( id="playertabledice_${id}" and id="blackdice_${id} ) to my players' panel but can only add one
Here is my attempt to add the 2 containers- it seems there is a problem with my "jstpl_player_board" declaration in .tpl
Code: Select all
var jstpl_player_board = '\<div class="cp_board">\
<div id="playertabledice_${id}" class="playertabledice"></div>\
<div id="blackdice_${id}" class="playertabledice"></div>\
</div>';
when I run my game.js, the line " dojo.place( this.format_block('jstpl_player_board', player ), player_board_div ); " results in a
"jstpl_player_board is undefined" syntax error
Code: Select all
for( var player_id in gamedatas.players )
{
var player = gamedatas.players[player_id];
var player_board_div = $('player_board_'+player_id);
dojo.place( this.format_block('jstpl_player_board', player ), player_board_div );
}
Can you please tell me what I am doing incorrectly or offer me any help
Thank you for any help!
Re: adding stuff to player panel - cannot get it error free
Posted: 03 July 2021, 08:02
by Tisaac
Why is there an \ before the first div ?
Re: adding stuff to player panel - cannot get it error free
Posted: 03 July 2021, 09:26
by developgame
Tisaac wrote: ↑03 July 2021, 08:02
Why is there an \ before the first div ?
Thanks for your response Tisaac!
the \ before the first div is there because I am following the example of how to add containers to the players' panel from studio doc's Game_interface_logic:_yourgamename.js"
https://en.doc.boardgamearena.com/Game_ ... amename.js
here is the example
Code: Select all
var jstpl_player_board = '\<div class="cp_board">\
<div id="stoneicon_p${id}" class="gmk_stoneicon gmk_stoneicon_${color}"></div><span id="stonecount_p${id}">0</span>\
</div>';
Re: adding stuff to player panel - cannot get it error free
Posted: 03 July 2021, 10:32
by Tisaac
In the example, there is a \ because it's a new line right after, which is not the case here. Try removing it
Re: adding stuff to player panel - cannot get it error free
Posted: 03 July 2021, 17:29
by developgame
Tisaac wrote: ↑03 July 2021, 10:32
In the example, there is a \ because it's a new line right after, which is not the case here. Try removing it
Thanks a lot Tisaac!
I did not know that \ stand for new line. That is really good information to know. Thanks!
Even after fixing the new line issue, I still had issues. I was able to get my two containers in by creating a parent container. Then putting the two containers I wanted to this parent container
Code: Select all
var jstpl_player_board = '\
<div class="cp_board">\
<div id="table">\
<div id="playertabledice_${id}" class="playertabledice"></div>\
<div id="blackdice_${id}" class="playertabledice"></div>\
<\div>\
</div>';
Re: adding stuff to player panel - cannot get it error free
Posted: 03 July 2021, 17:56
by paramesis
developgame wrote: ↑03 July 2021, 17:29
I did not know that \ stand for new line. That is really good information to know. Thanks!
It doesn't. It's an
escape character that prevents the newline immediately following it from breaking the string and causing a syntax error. The only reason to use escaped newlines in this situation is to make the template easier to read.
The errors you are getting are due to part of opening or closing div tags being escaped. One of your closing div tags has a backslash instead of a forward slash.
Re: adding stuff to player panel - cannot get it error free
Posted: 05 July 2021, 16:19
by developgame
paramesis wrote: ↑03 July 2021, 17:56
developgame wrote: ↑03 July 2021, 17:29
I did not know that \ stand for new line. That is really good information to know. Thanks!
It doesn't. It's an
escape character that prevents the newline immediately following it from breaking the string and causing a syntax error. The only reason to use escaped newlines in this situation is to make the template easier to read.
The errors you are getting are due to part of opening or closing div tags being escaped. One of your closing div tags has a backslash instead of a forward slash.
Thanks for the clarification and code advice, paramesis!