Page 1 of 1

[SOLVED] TableWindow : display strings with variable values

Posted: 20 October 2021, 11:43
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

Re: TableWindow : display strings with variable values

Posted: 20 October 2021, 13:24
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);

Re: TableWindow : display strings with variable values

Posted: 20 October 2021, 15:23
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() )
));