Multiple Restrict commands - is there a better way?

Hi all I am still struggling on with this Module but getting there slowly.

I have a Reserve Stockpile of ammunition in this game with a counter that counts down to Zero as Ammo is transferred from there. The Reserve has a Global Property called ChangeAmmo and is controlled by a Set Global Property trait. There is a Right-click menu for each gun which has the option to Take 10, 5 or 1 ammunition from the reserve. The problem I had was that if (for example) there was only 9 ammunition left in the reserve, but “Take 10” was selected, the Gun was topped up with 10 even though there was only 9 left. I was able to fix this and it works but I am using 3 separate Restrict traits for each of the Left-click options. The Restrict Commands disable the Left-Click options when they are greater than the remaining Reserve

My question; is there a more efficient way (ie One Restrict Command Trait with a more complex expression to cover all three commands)? If there is then I would need some help with it because I am limited to the simple ones used in the images below…

[Here](https://drive.google.com/file/d/1QK79kHK5MvvsMcgsHI7jHJxi_yi0OGo7/view?usp=sharing) is the module "B-17" as it stands so far if you want to take a look.

[EDIT] Never mind the download link it doesn’t work. if someone can suggest a good (free) way to fileshare I will try it.

Regards;

Darren

Hi Darren,

No, I don’t believe there is another way as RestrictCommands works on specifically named KeyCommands, these cannot be dynamically determined.

What you have done is quite efficient and easy to maintain, debug and improve. I wouldn’t get too hung up on trying to minimise the number traits until you have many, many more traits in a piece.

Regards.

1 Like

Assuming I understand the problem, IMHO you should re-architect your approach. Get rid of “Take1/Take5/Take10” and define a new single command “Take Ammo” which queries the user for how much to take and implements a check so they can’t take more than what is in Reserve.

Assuming you do what I suggest, the only time the command would need to be disabled is if the Reserve = 0.

2 Likes

Hello Brent;
It wouldn’t worry me except I am starting to notice some slight performance issues and I am nowhere near finished yet. The biggest performance hit was after I added a Startup GKC to make a Piece invisible at the start which affected the Startup speed significantly. Thank you for your time.
Regards;
Darren

Do you mean using the “prompt user to select from list” option in the Set Global Property? I don’t know how to do that. It asks you for a list of values. What values? Where do you get them from? I dunno. The “implements a check” thing also I have no idea what that is or how to do it either.

Regards;
Darren

11 traits is nothing, If you had 70, I would suggest looking at that.

Your performance issue is going to be the actual GKC execution time. There are some ways to improve GKC performance, and some improvements are being added into v3.7.

I would be happy to review your startup HKC if you want to post a screenshot.

That would be awesome Brent, here it is and thanks again

It might more a case of how I have done things because my knowledge of Vassal is limited, particularly when it comes to using expressions so I get around them in other ways where possible. If you have some tips about using Expressions I would be grateful.

regards;
Darren

I’m surprised that’s working at all. The Fast Match property name should be {“BasicName”} and the property value {“Ammo Stocker”}. What you have is trying to do something very different from what you are intending.

If you press the Help button, find the Startup Global Key Command section, you can see fromthe examples what these fields should look like. We try and keep the in-editor Help files up to date.

Regards,
Brent.

1 Like

Hello Brent;
Do you mean there should be “” on both the Piece Name and Property name in the Expression? The Expression Builder allowed it so I thought it was OK.

Regards;
Darren

Well about half of my GKCs had “” and the others didn’t so I fixed them all. The Startup is a little better now.

Regards;
Darren

Sketching out one approach.

  • Define GKC on piece (Ammo_Request)

  • Define a Dynamic Property (Ammo_Request_Amount)
    numeric checked; type = prompt user

  • Define Dynamic Property (Validated_Ammo_Request)
    This uses the logical expression function “? (expr ? r1 : r2)”
    {((Ammo_Reserve - Ammo_Request >=0) ? (Ammo_Request) : 0)}

  • Define Dynamic Property (Ammo_Level)
    Set Ammo_Level = Ammo_Level + Validated _Ammo_Request

  • GKC - Set Ammo_Reserve = Ammo_Reserve - Validated_Ammo_Request

Overall, this simplifies the user interface (UI) and puts the check for validity in the back end.

:face_with_spiral_eyes:Errrrrr… I am in way over my head here. So 3 x Dynamic Properties each named as you have them and with a GKC for the Piece as well. Which Piece? I am guessing the one used to represent the Ammo Reserve?

Validated_Ammo_Request Has the expression in the field called “Prompt”??? What do I have as the option next to it - Set Value Directly?

Ammo_Level

Set it how? If this is an Expression it does not work in the Expression Builder.

Sets to activate…what? I am not even sure if this is in the right Piece, maybe it should be in the other pieces which I use as ammunition track. Dunno! All this stuff is foreign to me.

Regards;
Darren

Darren -

My example was intended to provide an approach to fixing the issue. The specifics examples use what is called “psuedo-code” which outlines what needs to be done in human readable format, without going into language/script specifics.

Getting stuff to work in Vassal involves a learning curve, you have to try stuff out, figure out why it doesn’t work, change, etc.

But to help get you started, illuminating a couple specifics…

Define GKC on piece (Ammo_Request)

Define a Dynamic Property (Ammo_Request_Amount)
numeric checked; type = prompt user

Define Dynamic Property (Ammo_Level)
Set Ammo_Level = Ammo_Level + Validated _Ammo_Request

Hope some of this helps, but again it takes awhile to get things right and sometimes you end up having to back stuff out and do things differently.

Keep plugging away and before you know it, you will be a Vassal guru…

3 Likes

Hi Korval;
Thank you for the reply. Sorry to be a nuisance but what you call the learning curve with Vassal is very steep and yes mostly Trial & Error as you have mentioned, or as I prefer to say it - groping in the dark for answers. While it very decent of the people in this forum to give up their time to help, the answers given often lead to even more questions and that is because there is little in the way of explanation for how to do things, particularly Expressions. Take this Dynamic property for example,

referring to the part I have circled, three of the four options under “Type” are straight-forward enough but what of the 4th “Prompt User To select from list”? I think this option could be very useful but unfortunately the Help only says " The items in the list can be generated dynamically by Expressions." a page I have looked at many times and offers no description of how to add this list. so back to more groping in the dark and maybe after a full day I will find out how to do it but probably not.

Re “prompt user to select from list.” Why don’t you actually try that setting and see what happens next.

I did that and it asks me to create a list of values using Expressions. When I use the Expression builder it can return the value of another property but it does nothing. I can add the values from the current Dynamic Property (i.e Level numbers) and that creates a pop-up Prompt which allows me to select a value from that list which changes that Property but there is no advantage to this that I can see because all those values are already listed in the Right-click menu. A little more information would go a long way and save a considerable amount of time and exasperation on my part. I suppose I could spend the rest of the weekend searching through the 2000 modules and see if there is an example of this but I have other things to do.

Regards;
Darren

Hello Korval;
The Text next to the calculator symbol says to add a valid value. The only values I could get to work were those already within the Dynamic Property which is not very useful. Nice pic but it explains nothing, perhaps I should find something other than Vassal.

If you haven’t already, I’d spend time reading the Expressions reference page and the Property Match Expression page. You’ll have to determine whether or not you can surmount this barrier–if understanding and using expressions isn’t something you get comfortable with, you will either be making pretty rudimentary modules (there’s nothing wrong with that!) or as you suggest, perhaps moving on to another platform.

Is it possible that you are unintentionally interpreting the “can be generated” as “must be generated”? The prompt is just text given to the user in a popup. The list of choices you present to the user can be a list of text strings or numbers that you type into these boxes by hand (a “static” list) or values that come from other pieces/items in the module. “Dynamically generated” means to go fetch values from pieces, the map, as a result of arithmetic you perform on properties, whatever–either saving you the typing or giving you flexibility to present choices to the user that vary depending on the game situation, the current location, or anything else that changes during the course of play. Example–if for game purposes you need a user to see the piece’s current location in the dropdown list of choices when you give them a prompt like this, if you put {"Greenland"} in one of the boxes, the user will always see “Greenland” as a choice, no matter where the piece is. If instead you put {CurrentZone} in the box, what the user sees as this choice will vary based on the piece’s zone (assuming you have zones defined and named on your map).