Referring to this screenshot may help put the stuff below in context.
[img=http://img502.imageshack.us/img502/2266/testingmodpicturebu9.th.png]
I am making a dice roller where I want the dice to be visible as discrete dice. I got this idea from the person that posted a dice roller example a few days ago here in the forums (or at least I found it a few days ago), because that example helped me understand the way Vassal works.
I made a button layout to choose the number of dice to be shown. It has action buttons over the numbers that store the number of the button that was pressed in a global variable, Number_Pressed.
I made a die Prototype and created 5 At Start stacks of die images using this prototype. I stored the position (1-5) of each specific die in its respective At Start stack, using a marker called Position_of_die.
I made another button to start processing the dice images once the user is satisfied with the number of dice to be shown. It sends out a global key command, ALT CTRL R (for Roll), that gets picked up by any piece with a Position_of_die between 1 and 5. (This part seems to work fine. If, for example, I change the ALT CTRL R global key command definition to affect only dice with Position_of_die values between 1 and 3, only the first three die images are affected by later commands).
I plan to put the die images in layers and have the layers tied to the results of the Java dice roller or the ShadowDice roller (haven’t gotten far enough to decide). I want to control visibility of each individual die by defining their Basic piece image as a transparent .PNG, so that when layers are turned off, the die is not visible (for the sake of this test module, though, I made them a black square so they could be seen for testing purposes).
I put a Trigger Action in the Basic Die prototype that turns the global key command ALT CTRL R into a key command ALT CTRL S (for Show/Hide) that activates/deactivates the layers for each individual die. I have a conditional in this Trigger Action which states that an ALT CTRL S should be triggered by ALT CTRL R ONLY when the Number_Pressed global property is greater than Position_of_die, which is an individual piece marker.
What I’m trying to accomplish is this. All dice start visible in my module (in the testing module, they all start with layers off, but I don’t think it matters for purposes of this discussion). I also assume that after each dice roll, between 1 and 5 dice will be visible until the next roll. So when I process the next roll, I want to hide (by turning layers off) each die image that will NOT be used. In other words, for any die whose position is greater than the number of dice the user wants to roll for the next roll, I want to toggle layer activation if two things are true:
(1) the layer is active, meaning that die starts visible before the roll and therefore needs to be hidden (for example, Basic_Die_Active = true)
and
(2) Number_Pressed < Position_of_die
So, if the user presses 3 to roll three dice, I want the fourth (3 < 4) and fifth (3 < 5) dice to be triggered by the Trigger Action, turning the ALT CTRL R into an ALT CTRL S and activating/deactivating the layer.
That’s where I’m going with this. Problem is, I can’t even get half of this conditional argument to work.
In the attached test module, I’m not even checking for visibility yet. I’m just trying to get the layers toggled on the correct dice. In the Trigger Action of the prototype for the dice (to read the ALT CTRL R, or that the dice were rolled, and turn that into ALT CTRL S to show/hide layers for the affected dice), I have the conditional argument Number_Pressed < Position_of_die. What I’m hoping is that each die will run the conditional, and for those whose position is greater than Number_Pressed, its layers will be activated/deactivated.
The problem is that ALL the die pieces think the conditional is being met and are toggling layers, not just the ones with Number_Pressed < Position_of_die. The debug script shows the right values for each die and Number_Pressed value, but it runs the Trigger Action anyway.
I cannot figure out why this conditional is triggering for ALL the die pieces and not just some. I added in debugging Report Actions to show me the values as I go, and the values seem to be correct the entire way. So the issue is with the conditional being met and triggering the Trigger Action when it should not.
As part of the debugging action, I changed the ALT CTRL R Global Key Command to affect only die positions 1 and 2. Both of these dice report (through a Report Action) that they are receiving the ALT CTRL R, and dice 3, 4, and 5 do not. So that works, and these two dice appear to be the only ones selected.
Then, to continue that debugging action, I choose Number_Pressed of 3. The two affeced dice should run the conditional (Number_Pressed < Position_of_die) as (3 < 1) and (3 < 2) respectively. So the conditional should be FALSE for EVERY piece that gets the ALT CTRL R keypress in the first place and the Trigger Action should NEVER activate for any piece. But it still does. So the problem again appears to be with the conditional, and not with my selection of game pieces.
Trying to brainstorm about what the issue is, I realize that, in the conditional, I’m comparing a Global Property to a Marker of a Game Piece. Is this the problem?
Is it a bug? Am I making a conditional that’s not allowed or am I not phrasing the conditional correctly? (I’ve tried enclosing both variables in $…$ and it makes no difference.) Is there an error in my code? I’ve typed it twice from scratch and the probem reproduced both times I wrote the code.
The attached code is about as simple and distilled as I could make it to illustrate the problem. I know this is a lot to ask, but I hope someone might be able to look at this and run through it and see what the problem is, because otherwise I’m stuck. The module should spit out some debugging info into the log window to let whoever looks through this know what’s happening as it works.