[SOLVED] TableWindow : display strings with variable values

Game development with Board Game Arena Studio
Post Reply
User avatar
Ottoreg
Posts: 16
Joined: 16 March 2021, 11:13

[SOLVED] TableWindow : display strings with variable values

Post by Ottoreg »

Hello,

I'm trying to display a string that contains variable values in my 'round result' tableWindow.

It is said in the game interface logic documentation that "you can also display a complex value with a template and associated arguments".

I followed the syntax used in the example provided, but I get an error message once the tableWindow is displayed that says the variable is not defined.

In this bit of code I push into the array $table the new row.

Code: Select all

array_push($table, array(
	"str" => clienttranslate( "Boss : ${boss_hp} hp"),
	 "args" => array('boss_hp' => $this->getBossHealth() )
	 )
);
Here is the code you can find on the documentation :

Code: Select all

$table = array(
      array( "one", "two", array( "str" => clienttranslate("a string with an ${argument}"), "args" => array( 'argument' => 'argument_value' )  ) ),
      array( "four", "five", "six" ), 
      array( "seven", "height", "nine" )
);
I surely miss something important here, but I cannot figure out what it is...

Your help will be very appreciated.

Thanks! :D
Last edited by Ottoreg on 20 October 2021, 15:23, edited 1 time in total.
User avatar
RicardoRix
Posts: 2541
Joined: 29 April 2012, 23:43

Re: TableWindow : display strings with variable values

Post by RicardoRix »

is it, that the item is an array, array. Whereas you are just making an array ?

Code: Select all

array_push($table, array(array(
	"str" => clienttranslate( "Boss : ${boss_hp} hp"),
	 "args" => array('boss_hp' => $this->getBossHealth() )
	 ))
);
btw, you can use table[] = new_item, rather than array_push( table, new_item);
User avatar
Ottoreg
Posts: 16
Joined: 16 March 2021, 11:13

Re: TableWindow : display strings with variable values

Post by Ottoreg »

Alright ! The solution was partly found thanks to you, Ricardo :D

I needed to use two dimentional array for this particuliar case as you said but I also had to use simple quotes instead of double quotes (which are used in the documentation). :roll:

And also thanks for the tip about array new items ^^

working code :

Code: Select all

$table[] = array(array(
                
                "str" => clienttranslate( 'Boss : ${boss_hp} hp'), 
                "args" => array('boss_hp' => $this->getBossHealth() )
));          
Post Reply

Return to “Developers”