Variable state description

Game development with Board Game Arena Studio
Post Reply
User avatar
Tisaac
Posts: 2736
Joined: 26 August 2014, 21:28

Variable state description

Post by Tisaac »

Hi !

I'm working on a game where some action might be mandatory or optionnal depending on some power, and I would like to be able to display either "You must move" or "You may move" depending on the context, without having to duplicate the corresponding state.
Is there any easy way to do so ? I tried to do :
'description' => clienttranslate('${description}')
'descriptionmyturn' => clienttranslate('${descriptionmyturn}'),
But the thing is that the variable ${description} is then not replaced when I do this :
$arg['description'] = clienttranslate('${playerName} may move a worker');
it's just printing "${playerName} may move a worker" instead of the string I want to display.

Any idea ?
Thanks !
User avatar
fafa-fr
Posts: 383
Joined: 22 December 2013, 21:58

Re: Variable state description

Post by fafa-fr »

Yes, if you have one of the strings in your states file (eg you must move ...), in your js file you can use when needed:

Code: Select all

this.gamedatas.gamestate.descriptionmyturn = _( "You may move a worker" );
this.updatePageTitle();
This is not in the studio doc, so I don't know what admins would think about us using this, but I saw it in some games (can't remember if it was in terra mystica, or a game developed by Alena)
User avatar
Tisaac
Posts: 2736
Joined: 26 August 2014, 21:28

Re: Variable state description

Post by Tisaac »

Thanks ! I was looking for that in the UI doc but couldn't find anything !
User avatar
Loreroth
Posts: 18
Joined: 05 August 2014, 07:28

Re: Variable state description

Post by Loreroth »

So for variables in strings to be interpreted the string needs to be done with double quotes " not single quotes ' .

You also don't need to translate a string with only a variable in it, 'description' => $description should be ok.
User avatar
hersh
Posts: 76
Joined: 12 December 2013, 23:49

Re: Variable state description

Post by hersh »

Try also setting $arg[‘playerName’] = “player”

I think the args get passed if I remember.
User avatar
Tisaac
Posts: 2736
Joined: 26 August 2014, 21:28

Re: Variable state description

Post by Tisaac »

Loreroth wrote: 15 May 2020, 01:36 So for variables in strings to be interpreted the string needs to be done with double quotes " not single quotes ' .

You also don't need to translate a string with only a variable in it, 'description' => $description should be ok.
But I don't want them to be interpreted since they are not declared at this point ! The '$you' variable is replaced latter on by the BGA framework.
So I was trying to use these variables but it seems that the string replace is not recursive :(
(whereas the notify system since to be recursive according to the doc)
hersh wrote: 15 May 2020, 06:42 Try also setting $arg[‘playerName’] = “player”

I think the args get passed if I remember.
I will try that! Because if I just used the player name from gamedata, there is no 'span' element around it with the right color.
User avatar
Loreroth
Posts: 18
Joined: 05 August 2014, 07:28

Re: Variable state description

Post by Loreroth »

Ah, sorry I seem to have misunderstood.
Post Reply

Return to “Developers”