[messages] [Module Design] Calculated properties

Sebaestschjin sebastian.naehring at gmail.com
Fri Apr 11 18:33:31 CEST 2014


Okay, I try to explain what those CalculatedProperties are good for,
based on my own experience with Vassal so far.

Roughly spoken a "CalculatedProperty" (CP from now on) as similar to a
"DynamicProperty" (DP form now on) which is set to "Set value directly",
but with one important distinctions: It doesn't need a trigger to
change. It will change immediately whenever a property of the associated
expression changes. The expression of a DP will be calculated only once,
for every trigger it receives. A CP will always be recalculated. I think
a CP best works togehter with the "GetProperty()" function you can put
into expressions. I can try to demonstrate this with an example I am
using for my module.

I have a deck of cards. Each card has two different properties (triangle
and circle) where each property can have a value between 0 and 5. I now
want a label between the deck which counts the number of cards in the
deck where the triangle property equals 1. This can be done with the
deck option "Perform counting of property expressions". And I then can
use a TextLabel with the name of the property as its value. However now
I want a button which changes the content of the label. When I press the
button, the label shouldn't print the number of cards where the triangle
property is 1, but where the circle property is 1. That's where the CP
with the "GetProperty()" function comes into play. My CP is specifyed
as:

Value = GetProperty($DeckName$ + "_" $Property$)

And the Textlabel I mentioned before now has the content: $Value$. My
button now changes the property $Property$ to "Circle" which immediately
leads to a reevalutation of $Value$ and the new value can be seen in the
label. Of course you could also use a DP instead and set the property
$Value$ within the DP, but the power of the CP is its flexibility. I
combine different CP within a prototype, which each calculate different
stuff, depending on the properties given. I need this type of
calculation in different places of the module but based on different
concrete property values. So I use this CP in a prototype and add marker
traits to the pieces where I need the calculation results. This way I
can easily use expressions within a gamepieces without worrying abouts
where they come from.

I hope I somehow could make clear, what I mean and what the benefits of
CP are. I think they are bessed used in prototypes that perform typical
calculations you will need in different places of your module. If you
want I could make a sample module including the example I talked about.
It's actually a little more complex than I explained, but I wanted to
keep it as short as possible.

_______________________________________________
Read this topic online here:
http://www.vassalengine.org/forum/viewtopic.php?p=44492#p44492


More information about the messages mailing list