adding stuff to player panel - cannot get it error free

Game development with Board Game Arena Studio
Post Reply
User avatar
developgame
Posts: 107
Joined: 15 June 2020, 20:56

adding stuff to player panel - cannot get it error free

Post 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!
User avatar
Tisaac
Posts: 2743
Joined: 26 August 2014, 21:28

Re: adding stuff to player panel - cannot get it error free

Post by Tisaac »

Why is there an \ before the first div ?
User avatar
developgame
Posts: 107
Joined: 15 June 2020, 20:56

Re: adding stuff to player panel - cannot get it error free

Post 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>';
User avatar
Tisaac
Posts: 2743
Joined: 26 August 2014, 21:28

Re: adding stuff to player panel - cannot get it error free

Post 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
User avatar
developgame
Posts: 107
Joined: 15 June 2020, 20:56

Re: adding stuff to player panel - cannot get it error free

Post 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! :D

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>';

User avatar
paramesis
Posts: 398
Joined: 28 April 2020, 05:00

Re: adding stuff to player panel - cannot get it error free

Post 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! :D
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.
User avatar
developgame
Posts: 107
Joined: 15 June 2020, 20:56

Re: adding stuff to player panel - cannot get it error free

Post 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! :D
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!
Post Reply

Return to “Developers”