Page 1 of 1
Can you use arguments with this.setClientState?
Posted: 02 December 2019, 21:16
by VanHlebar
I am transitioning to a clientState and I would like to be able to use an argument in my description. Is this possible? I have tried the following but it keeps giving me an error:
Code: Select all
this.setClientState("client_PlayerPlaceCaballeros", {
descriptionmyturn : _("${you} may place ${cabs_to_move} caballeros on the board."),
cabs_to_move : this.clientStateArgs.cabs_avail_to_move
});
The javascript error I get is the following:
Invalid or missing substitution argument for log message: ${you} may place ${cabs_to_move} caballeros on the board.
Re: Can you use arguments with this.setClientState?
Posted: 02 December 2019, 21:47
by tchobello
hi !
You should have a look at the complete description of States ( and use 'args' line)...
http://en.doc.boardgamearena.com/Your_g ... es.inc.php
Re: Can you use arguments with this.setClientState?
Posted: 02 December 2019, 22:30
by VanHlebar
I did look at that and tried to follow that, however this is on the client side so I wasn't sure if the same theory held true. I am not going back to the server at this stage as there is no need to do so yet.
I was trying to follow the example in the Cookbook area of the documentation but since this.setClientState is undocumented, I was unable to see if using variables like this is even valid.
Thanks,
Eric
Re: Can you use arguments with this.setClientState?
Posted: 03 December 2019, 05:42
by hersh
try using the parameter named "args"
Code: Select all
this.setClientState("client_PlayerPlaceCaballeros", {
descriptionmyturn : _("${you} may place ${cabs_to_move} caballeros on the board."),
args: this.clientStateArgs <------- make sure this object has "cabs_to_move" property defined
});
Re: Can you use arguments with this.setClientState?
Posted: 03 December 2019, 12:39
by vincentt
Hi,
I concur you need to use args.
You can look at DiceForge code, we use some and we use the args parameters
Vincent
Re: Can you use arguments with this.setClientState?
Posted: 03 December 2019, 13:13
by VanHlebar
Awesome thanks for the direction folks I appreciate it!
Re: Can you use arguments with this.setClientState?
Posted: 03 December 2019, 23:58
by vincentt
hi,
In DF code, you will see that we have a function to go back to server state.
Also, take care to reset your variable when you go out of the client state, as it can be persistent and triggers some erratic behavior (we had some "fun" time to understand our issues)
Vincent
Re: Can you use arguments with this.setClientState?
Posted: 04 December 2019, 03:43
by VanHlebar
Thanks for the "warning", I already had experienced some of those "interesting" times when I forgot to reset my clentStateArgs variable.
It just seems silly to me that I have to go back to the server just so that I can pass these args back to the the client, when I already have ALL the information I need for that specific client state. If this is the only way then so be it, but it just seems like a wasted call back to the server. I did get read access to your project and was going to poke around at it this evening or tomorrow.
Thanks again so much for the assistance!
Eric
Re: Can you use arguments with this.setClientState?
Posted: 04 December 2019, 12:47
by vincentt
Hi,
When you do a client state, you do not go back to the server, you stays in the JS. The args parameters is necessary as you enter in a new state, managed by the JS framework. So this is used to initialize your state

I may be missing why you think you need to go back to the server for this..
Vincent
Re: Can you use arguments with this.setClientState?
Posted: 05 December 2019, 03:33
by VanHlebar
hersh wrote: ↑03 December 2019, 05:42
try using the parameter named "args"
Code: Select all
this.setClientState("client_PlayerPlaceCaballeros", {
descriptionmyturn : _("${you} may place ${cabs_to_move} caballeros on the board."),
args: this.clientStateArgs <------- make sure this object has "cabs_to_move" property defined
});
Ok not sure how I completely over looked your response earlier! This is what I was looking for and somehow just missed it completely. Thanks so much for the help to all of you! I promise to read better.
