Page 1 of 1

Variable state description

Posted: 14 May 2020, 11:41
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 !

Re: Variable state description

Posted: 14 May 2020, 14:45
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)

Re: Variable state description

Posted: 14 May 2020, 15:46
by Tisaac
Thanks ! I was looking for that in the UI doc but couldn't find anything !

Re: Variable state description

Posted: 15 May 2020, 01:36
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.

Re: Variable state description

Posted: 15 May 2020, 06:42
by hersh
Try also setting $arg[‘playerName’] = “player”

I think the args get passed if I remember.

Re: Variable state description

Posted: 15 May 2020, 17:07
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.

Re: Variable state description

Posted: 15 May 2020, 23:13
by Loreroth
Ah, sorry I seem to have misunderstood.