Ok I have a layer with 7 levels how to dive it with dynamic value?

It’s a turn die roll modifier that goes from -3, -2, -1, -0, +0, +1, to +2. Everytime the counter changes facing and the dynamic property is above -1 aka layer level 3 I want to set it it to level 3 aka -1 displayed! otherwise just reduce the layer by 1.

Everything I’ve tried sees the level drop to below 1 as the -3 shows -3 on multiple straight moves that increase the level by 1.

I’ve fought this for 3 hours and nothing I try works! I’m using 3.7.22 of vassal thanks I’m a brick head apparently

Sorry, but I’m not quite clear on what it is you want to do.

I think, what you want, is for the Dynamic Property to take on value -3,-2,...,+2, the Layer to use the same values for the layers, and when the Dynamic Property changes value, then the Layer to change accordingly. If so, then do

  • Dynamic Property
    • Name: DRM
    • Numeric: true
    • Minimum: -3
    • Maximum +2
    • Command: …
  • Layer
    • Name: DRM_Face
    • Levels follow expression value: true
    • Expression: {DRM}
    • Level 1=: -3

Whenever the property DRM changes value, then a newl layer will be shown.

If this is not waht you want, please try to explain it a bit more.

Note that Expression above can be as complicated as you want. Also note, that when you select Levels follow expression value then you can no longer change the level directly by user commands.

Yours,
Christian

Christian, did you take into account that the OP has defined counter values for both -0 and +0?

As a mathematician, I assumed that to be a mistake :smile:

The double zero is to create a recovery effect from high g turning so the pilot has to move straight multiple hexes to recover from the negative effects of the turn.

My thoughts were that the -3 in layer 1 had a layer value of 1. -2 layer level 2 the goal is anything above layer level 3 aka -1 image would be reset to -1 or level 3. Anything already level 3 or less would be a minus one to the level. As a turn gives you at least a -1 die roll mod. While flying straight slowly increases the level to level 7 or +2 image

I think we need a bit more information:

  • What will instigate a change in the Layer? Or perhaps, when will a change occur?

Perhaps you could point to your module, so it is easier to see in action what it is you want to achieve.

It sounds like, but correct me if I’m wrong, what is happening is something like

  • A plane is given a command. Those commands could be, for example,
    • Turn left
    • Turn right
    • Continue straight
    • Climb
    • Dive
  • Then, when the turn ends, the new heading and pitch of the plane is calculated, and the Layer changed accordingly.

In that case, what you could have is something like

  • Dynamic Property
    • Name: Pitch
    • Numeric: true
    • Minimum: -3
    • Maximum 3
    • Commands:
      • Turn Left
        • Key: turnLeft
        • Type: Direct
        • Expression: {Math.max(-3,Pitch-1)}
      • Turn Right
        • Key: turnRight
        • Type: Direct
        • Expression: {Math.max(-3,Pitch-1)}
      • Fly Straight
        • Key: flyStraight
        • Type: Direct
        • Expression: {Math.min(3,Pitch+1)}
      • Climb
        • Key: climb
        • Type: Direct
        • Expression: {Math.min(3,Pitch+1)}
      • Dive
        • Key: dive
        • Type: Direct
        • Expression: {Math.max(-3,Pitch-1)}
  • Calculated Property
    • Name: PitchLevel
    • Expression: {(Pitch + (Pitch <= 0 ? 0 : -1) + 4)}
      (Pitch values map like -3 → -3, …, 0->0, 1->0, …, 3->2 i.e., double 0, and then add 4 to put it in the range from 1 to 6)
  • Layer
    • Name: Pitch_Face
    • Levels follow expression value: true
    • Expression: {Pitch}

Of course, commands turnLeft and turnRight should also envoke a Can Rotate trait, to change the heading of the plane.

Yours,
Christian

Decouple the drm and the layer levels. For the dynamic property think solely in terms of levels. The range of the dynamic property should match the 7 layers. Either 1..7 or -3..+3, whichever better matches the mental model. The minimum value must match the layer’s “Level 1=” value. For straight moves the upper limit must be constrained while for turning moves both the upper and lower. Assuming the dynamic property name is “level” and the range is -3..+3 the “Key Commands” are:

  • Straight: {Math.min(3,level+1)}

  • Turning: {Math.max(-3,Math.min(-1,level-1))}

Adjust the min/max values if using a different range.

Use a Calculated Property for the drm: level<1?level:level-1

Actually only worried about turning not climbing or diviing.

So apparently this command is somehow setting the variable to -1
{Level_Layer_FM >= 4 ? {3} : (Level_Layer_FM-1)}

So what is the correct syntax to get this to evaluate the unit as being level 4 or higher and setting the value back to 3 or even subtracting 1 from the value when it tests false. Based on having it post the value in chat it appears to never test false and always somehow sets the value to -1!

While the images display -3,-2 etc. I am assuming the first layer that is the -3 image is level 1.

That if condition is in this:

Found the problem after fixing the reversed name (new level of dyslexia!) it works fine. So I’m putting the keyboard down and stepping away from the mouse before someone gets hurt! :wink:

You do want to be using the Math.min/max functions. The “Set value directly” expressions don’t honour the min/max values. To try that out: add a text label to display the dynamic property then just keep going straight. The value will exceed the maximum value definition. The layer trait properly handles the over-range, but if you use the dynamic property for anything else you may be surprised.

For straight (Ctrl-S) to not exceed 7: {Math.min(7,Level_Layer_FM+1)}

For turns: {Math.max(1, Level_Layer_FM >= 4 ? 3 : (Level_Layer_FM-1))}

Although my preference would be: {Math.max(1,Math.min(3,Level_Layer_FM-1))}

You don’t need the extra curly braces around the number 3.

I didn’t notice the naming issue until you pointed it out. :smile:

Edit: for the straight movement you could use “Increment numeric value” with 1 and not require min/max limiting. It won’t increment past the upper limit.

Here’s an idea.

use the following values…

-7, -5, -3, -1, +1, 3 ,5, 7, but interpret those as fixed-point numbers, with 1 fractional bit, so that semantically, they mean -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5.

when changing the value, add or subtract 2 rather than 1.

However, when USING the value, so that all of the logic based on the current value

use (value / 2) (do NOT use >> 1, because -1 shifted right (logical) 1 bit turns into MAX_SIGNED_INT_, and -1 shifted right (arithmetic) remains -1. These are the two edge cases of 1’s complement signed number notation.