Create account / Log in

Dynamic token values possible?

Talk about module design ideas and techniques.

Moderators: uckelman, Tim M

Dynamic token values possible?

Postby snoozefest » September 1st, 2020, 11:19 pm

Is it possible to set the value of a token property based on where on the map the token is located? For example, if I have a market area with 3 boxes for values 1, 2, and 3, can I drag a generic token into the 1 box and have that token's value set to 1 (or 2 or 3 if I go to those boxes instead)? Then, once I've made all my purchases, I could drag everything to another box, my shopping cart, which would display the sum of all the token values?
snoozefest
 
Posts: 3
Joined: March 18th, 2011, 1:24 pm

Re: Dynamic token values possible?

Postby grouchysmurf » September 10th, 2020, 4:51 am

Sure.

Add irregular grid to your market area boxes. Make the market area boxes read location from $gridLocation$. Named them locations accordingly.

Give each token a calculated property. Have it calculated as per If(CurrentZone=="Market Area", stuff, not stuff).

Give each token a text label to display its value.

EDIT: to sum up value of tokens in an area: http://www.vassalengine.org/wiki/How_to ... tion/state.
User avatar
grouchysmurf
 
Posts: 178
Joined: August 9th, 2011, 7:48 pm

Re: Dynamic token values possible?

Postby snoozefest » September 10th, 2020, 8:54 am

Thanks, but unfortunately that won’t quite work for my goal. What I had hoped to do was to assign those values as you suggest, but then have the player drag out only what they want to buy from the market. They would drag it to a “Buy Box” which would then add up all those values and show them the total they need to pay.
snoozefest
 
Posts: 3
Joined: March 18th, 2011, 1:24 pm

Re: Dynamic token values possible?

Postby JoelCFC25 » September 10th, 2020, 2:36 pm

grouchysmurf wrote:Have it calculated as per If(CurrentZone=="Market Area", stuff, not stuff).


Isn't this no longer a best practice? I thought the new supported syntax was of the form:

Code: Select all
expression ? true-result : false-result
JoelCFC25
 
Posts: 748
Joined: October 12th, 2010, 5:15 pm
Location: Minnetrista, MN

Re: Dynamic token values possible?

Postby rprasadusa » September 10th, 2020, 2:42 pm

I need the tokens to retain their value so that, when a bunch are dragged to the shopping cart, the total value is automatically calculated and displayed.
rprasadusa
 
Posts: 6
Joined: September 6th, 2020, 6:03 pm

Re: Dynamic token values possible?

Postby grouchysmurf » September 10th, 2020, 5:10 pm

Old habits die hard.
User avatar
grouchysmurf
 
Posts: 178
Joined: August 9th, 2011, 7:48 pm

Re: Dynamic token values possible?

Postby grouchysmurf » September 11th, 2020, 4:45 am

rprasadusa wrote:I need the tokens to retain their value so that, when a bunch are dragged to the shopping cart, the total value is automatically calculated and displayed.


Sure. That is what that IF or condition ? if_true : if_false. The calculated value will be updated if and only if token's current zone is MARKET. Whenever it leaves this zone, its value will not be changed i.e. it will be retained.
User avatar
grouchysmurf
 
Posts: 178
Joined: August 9th, 2011, 7:48 pm

Re: Dynamic token values possible?

Postby grouchysmurf » September 11th, 2020, 5:15 am

JoelCFC25 wrote:
grouchysmurf wrote:Have it calculated as per If(CurrentZone=="Market Area", stuff, not stuff).


Isn't this no longer a best practice? I thought the new supported syntax was of the form:

Code: Select all
expression ? true-result : false-result


I believe it needs to be announced loudly and clearly: so far I only saw forum comments and replies to bugs. Or maybe I missed something?
User avatar
grouchysmurf
 
Posts: 178
Joined: August 9th, 2011, 7:48 pm

Re: Dynamic token values possible?

Postby rprasadusa » September 11th, 2020, 10:46 pm

I appreciate the help but these examples, "stuff" and "not stuff", just aren't specific enough for me to figure this out. Are there any modules that do this sort of thing that I can take a look at?
rprasadusa
 
Posts: 6
Joined: September 6th, 2020, 6:03 pm

Re: Dynamic token values possible?

Postby grouchysmurf » September 12th, 2020, 8:11 am

Here, d/l this module: https://www.dropbox.com/s/qz1u23gp44vud ... .vmod?dl=0

Token value is set to 0 when it leaves zone named "market", you may want to change this behaviour.
User avatar
grouchysmurf
 
Posts: 178
Joined: August 9th, 2011, 7:48 pm

Re: Dynamic token values possible?

Postby rprasadusa » September 12th, 2020, 10:09 am

Thanks, that does help! What do you change "0" to to get a null effect, so the token retains its previous value?
rprasadusa
 
Posts: 6
Joined: September 6th, 2020, 6:03 pm

Re: Dynamic token values possible?

Postby rprasadusa » September 12th, 2020, 10:41 am

THANK YOU! I think I've got it now, coming soon to a Power Grid module near you!
rprasadusa
 
Posts: 6
Joined: September 6th, 2020, 6:03 pm

Re: Dynamic token values possible?

Postby grouchysmurf » September 12th, 2020, 4:04 pm

Happy to hear it worked for you. To have token retain its value I would use:

Code: Select all
CurrentZone == "market" ? LocationName


i.e. get rid of " : 0" (which is ELSE condition in the above IF-ELSE statement).
User avatar
grouchysmurf
 
Posts: 178
Joined: August 9th, 2011, 7:48 pm


Return to Module Design

Who is online

Users browsing this forum: No registered users and 7 guests

cron