Attachment Index?

Hi all;
The title is my question. When using Attachment as a Property match in a Trait GKC, the option appears for “Basic Name or Attachment Index”…

…how do I find the Attacment Index and what is it? I can’t find anything in the Documentation.

Regards;
Darren

When the Attachment trait is used on a Piece it may form an attachment to several other pieces. The Index field allows you to process each attachment - for example, using a trigger loop.

It will be an integer, starting (if I recall correctly) at zero.

1 Like

Hello Mark. Thanks for the tip.

I found some info for this under Trigger Trait and Action Button in the guide. Not sure how or why I would use it yet though. Thanks.

Darren

I’ve used Attachment trait extensively in the development of Commands & Colors: Napoleonics v5. It’s fair to say, I couldn’t have done without it. In all that, I’ve used attachment index for one case - placing markers on a number of other pieces without needing any traits on the target pieces:

This example shows the key Trigger trait that traverses one set of attachments - Infantry pieces as it happens. Property “inf” is the index value for subsequent calls to GetAttachProperty(), which is the equivalent function to the GKC that you showed earlier. The example also demonstrates that the index in fact starts at 1:

And here is the Index in use - allowing the calling piece to place the new marker at the same location as each Attached piece, in turn. GetAttachmentProperty() is used to find out the CurrentX / Y of each piece. Note that unitClass will have been set to “inf” - by the above Trigger example’s “setINF” Key Command - it is both the Attachment name (first parameter) and the name of the Index property (third parameter):

2 Likes

Hello Mark;
A very complex example and way beyond me at this stage. I have worked out that the offset fixes the position for placement relative to the issuing piece and the reciever of the Place Marker. There is much about Attachments I find difficult. For one thing the fact that a GetAttachmentProperty() only works on the first attachment.

GetProperty(unitClass) is the Index for the Trigger which will change each time it fires…yeah…not sure how the rest works :slightly_smiling_face: more time is needed. I will have to look at your Module to understand (maybe) what is being done.

Darren

Going back to your original question, access to the other attachments is exactly the purpose of the Index - whether via a GKC Attachment match or via GetAttachmentProperty().

There is a new learning curve and anything that attachments can do is, in theory, possible using Global Key Commands, passing data between pieces using Global Properties. It just more efficient using Attachments. A cue that it’s worth the effort to get into, is when you are finding that you want to use the GKC/GP method a lot and especially when it’s the same group - or subset of - that you are wanting to process with multiple GKC calls.

I will offer more help if / when you are ready to try something specific. The CCN module gives the new functionality a good workout and demos some of what can be done with it but it is not the best educational tool.

Hello Mark;
I have looked through the CCN module and I understand all you have done except the last part of both your offset Expressions for the Place Marker Trait. If the format is GetAttachProperty(attach, prop, index) , why use
GetProperty(unitClass) instead of referencing the actual name of the Index Property? So for Y offset it would read:
{CurrentY - GetAttachProperty(unitClass, "CurrentY",inf)}

The GetProperty() function is a little confusing for me, according to the guide it has limited uses and when I have experimented with it, {GetProperty(Damage)} for example, or {GetProperty(“Damage”)} will return the same value as {Damage} and is always a Property within the issuing Piece.

[EDIT] Actually, {GetProperty(Damage)} , without the “” doesn’t do anything, which is similar to what you are using in the Place Marker Trait. Perhaps it only works in an Expression?

Regards;

Darren

As you’ve found there is a difference between {GetProperty(Damage)} and {GetProperty("Damage")} . The second form is indeed exactly the same as {Damage}

The first form is doing something that can be very useful, it is returning the value of a property the name of which is held in another property - in this case - “Damage”. Let’s suppose property “Damage” equals “34”. You’re getting a null return because a property named “34” doesn’t exist in your example.

Similarly, you can use a property to hold the name of an Attachment.

In my case, unitClass is the name of one of three different types of pieces; inf, cav and art. I’m doing it this way so that the single Send to Location trait will act on different types of piece depending on what the value of unitClass is.

In particular, my example is being called from three distinct Trigger Action loops - one of which deals with “inf”, the other two with “cav” and “art”. In my experience, Trigger loop index names need to be unique, therefore I have named each one after the class of piece that it is processing.

Ok and that is what you are doing in the example…yes? If there were only one unitClass then {CurrentY - GetAttachProperty(unitClass, "CurrentY",inf)} would work? There is a lot here to get my head around, the Guide does not specifically say you can return a Property value within a Property…or that is not how I interpret it.

Since I found out about the Index I have used it to send the same command into a set of “Zones” in sequence with success although I don’t know if it is really more efficient than having a series of GKC (8 in my case previously) in the correct Trait order so they fire one after the other. Performance seems to be the same, only advantage is 7 less Traits in the Piece.

An inconsistancy for me with GetProperty() is that with a Global Property, sometimes {Damage} will not work where {GetProperty(“Damage”)} will and also the Simple Expression $Damage$ always works. Very confusing.

Regards;
Darren

{Damage} and {GetProperty("Damage")} should be functionally identical. Are you sure you didn’t make a typo somewhere? If not, a bug report should probably be filed.

FYI, GetProperty() has 2 primary uses:

  1. To add a level of indirection, as with Mark’s GetProperty(unitClass)
  2. To reference a property whose name includes spaces (or possibly other characters that are illegal in Java identifiers) within BeanShell code, such as {GetProperty("Unit Class")}–{Unit Class} would try to look up 2 separate properties, Unit and Class.
1 Like