[messages] [Module Design] Calculated Property - Timing of Calculation and ???s

Brent Easton b.easton at exemail.com.au
Mon Aug 19 18:19:08 MST 2013


> This answers a big question of mine, as I thought you had to add a
> trigger in there somewhere to specifically force the CP to calculate.
> Man, that's gonna simplify some code in a hurry!


Yes, but it means you have to be careful. If you have a complex CP that
is being re-calculated often (e.g. every time a piece is redrawn), then
you may experience performance issues.


> Ah...I was thinking of this in terms of addition in Java and I messed
> up the code. "Cards" should be "Total". Oops. :oops: I wanted to
> increment the total number of cards by 1. If I had used "Total", would
> this work, or would I need to code it differently?


A CP has no side effects - it cannot change any global properties or
trigger any other traits. To increment a property named Total by 1, you
would need to use a Set Global property, or Dynamic Property trait
appropriately triggered.


> Is there a way to use null for anything at all, or is that an invalid
> parameter at all times? Should I always use the "empty string"? The
> reason I'm being this specific is that I need to check for whether
> some items are "offboard" or not. In the past, using "offboard" as a
> parameter didn't work, so I had tried using "null", meaning that the
> piece did not have a valid location set, but to no avail. Would "empty
> string" be the logical way to handle this at present, or is there
> something that I'm missing?


Java does not have the concept of null, so it it cannot be used in a
beanshell expression. The empty string "" is equivalent to null. If
property xxx has no value then {xxx==""} is true. 

A piece will report it's location as "offboard" if it is in a border
defined around the edge of a board. In this case, comparing to the
string "offboard" should work. Depending on how you have set up boards,
maps, and zones, pieces may return any location name at all including
"". In this case, comparing to "" should work.


> Also, on a somewhat related note, has anyone expressed interest in
> setting up a howto or "learn by example"-type subforum for coding?
> I've been doing a lot with automation and I know Dr. Nostromo has in
> the past as well. If I was to submit some of my examples or code
> walkthroughs, where would be the best place--here in Module Design, or
> in a different/new location? Just wondering...it's taken me a while to
> figure some of this stuff out, but I'd love to learn more and trade
> ideas.


The wiki would be the best place for this. The wiki needs a friend to
sort through it, re-organise and bring it up to date.

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


More information about the messages mailing list