Problems with triggering a layer using preexisting property

Hello everybody,
I’m new to module design ; I think I have a decent grasp of the traits etc… but I’m still a beginner.

My problem is about triggering the next below layer level to show up.
Quick intro : I’m making a morale system for units. It is displayed on the counter by several levels of the same layer with each level being a coloured indicator of the morale status.
Basically the morale system uses upper and lower thresholds with each range corresponding to a colour. For example between 80 and 100 of morale you are “green”, between 60 and 80 “orange” and so on.
To keep track of the actual value used to determine in which range you fall I use a Dynamic Property which is modified everytime the player clicks on entries in the right-click context menu of the unit’s piece. By entries I mean like “casualties”, “losing combat” etc… with each one leading to a (positive or negative) incrementation of the Dynamic Property.
This has been tried and works as intended.

Now comes the issue. I would like to automate the change of the coloured indicator (that is : the level in the morale layer). The keystroke assigned to a morale reduction is Ctrl+M.
I made a Trigger Action with the following caracteristics :

Trigger when properties match : {morale_value <= 80}
(morale_value is the name of the property keeping track of that, mentioned above)
(…) (fields left blank)
Perform these Key Commands : Ctrl+M

Ctrl+M is defined in the layer Trait as the keystroke to hit to go to the next worse morale status indicator.
Since the unit starts with green morale, triggering Ctrl+M should show the next lower morale indicator.
But it doesn’t work. Nothing happens.
Ctrl+M itself works because when I do it manually it does what it’s supposed to do.

I suspect the Property match expression to be faulty but I tried many times with/without $…$, written this way or the other way around, for test purposes I even tried == instead of <= etc…
I’ve been looking through the forum and I didn’t find a previous thread addressing my issue and nothing that looks like it.

I acknowledge that such an automation is purely optional as again the manual, ‘hard’, way works but it would be more convenient and I do believe it is possible to make it work.
I hope I was clear enough.

Thank you very much !

Can you post a screenshot of your Layer configuration?

Typically if you want to link the displayed level of a Layer to a Dynamic Property (this is the Levels follow expression value setting of a Layer), you should not need a Trigger at all if you configure the Layer correctly. But maybe seeing what you’ve configured will shed light on some other thing you’re attempting to do.

Tell me if that helps you, or if you need more explanations about my weirdo ‘programming’ ^^
Thank you !

Edit : following your advice I’ve taken a look at the levels follow expression value part of the Layer configuration window but as far as I understood I only can tell it which value corresponds to level 1 but what about the evolution of that value ? The config window doesn’t ask for anything but the first value-level pair. But I’m surely missing something…

That’s right, you’re very close now. The changing of the property will all occur in the Dynamic Property trait with the keystrokes you assign for incrementing/decrementing. In the Layer trait you just need to tell it what numeric value of the property corresponds to the lowest level image.

Example: If my Dynamic Property (and thus all the various images I have in my Layer) can range from -2 to +4, I should have 7 images for all integer values in that range, and I’d set the box for the Level 1 = to a value of -2. Then even if you set the initial value of the Dynamic Property to something in the middle of the range, the Layer knows how to cycle between the values correctly.

OK. I will try this out right now.
Unfortunately, my dynamic property ranges from something like -50 to +100 so that makes for a lot of levels but I’ll look into it.
Thank you very much and I’ll tell you what happens over there !

OK, let’s puzzle this out further. How many different images do you mean to display? Setting up the Layer this way (requiring 150 levels) makes no sense if you only have a handful of possible images to display. So in that respect you were on the right track–apologies for the misdirection. We simply need to get the process you started with working as pictured in your originally shown Layer config.

Can you also post a screenshot of the Trigger you were configuring?

Allright, I think I’d rather do it this way :grinning:
Actually there are 7 images.
There might be another problem though : I originally planned to portray the morale using percentages of a set morale value defined at the unit level so to speak… I mean every unit type would be granted a basic morale value in its definition and the dynamic percentage of that definition would lead to the proper coloured indicator to be displayed… However for the sake of simplicity let’s forget about that first (and even still, I think I have an idea to circumvent that problem if I come this far).

Here is the trigger :

After thinking some more I suspected this might be the case. Your problem is circled in red. A Trigger must have a key command to actually function. It doesn’t have to be something a user can actually do via the keyboard, so a Named Command would be ideal here as it’s “behind the scenes” functionality.

And whatever *** name would work ? for the key command

Sure, Named Commands are simply alphanumeric strings. I typically use something that will remind me later when a lot of time has passed what the thing is actually doing. Maybe demotePiece or lowerRank or anything you can think of that’s unique.

OK so I used this but it doesn’t work… so maybe it is the PME that fails…

I reviewed my property and :

  • it is numeric and starts at 0
  • different entries increase/decrease that value (BTW i made a small dynamic text label next to the
    counter to follow the evolution of the value during the tests)
  • when I artificially raise the value above 20 using those entries nothing happens, the layer level doesn’t change… although the value itself is indeed going up and down exactly as ordered.
    The syntax corrector doesn’t seem to be complaining either…

I think I would need to see the whole module to pinpoint where it’s falling down, but I think some more logic is required. It’s not simply that you need to know how big/small morale_value is, but that its value is currently right at one of the thresholds and the keystroke adjusting that property is happening. Only then do you want to change what image is shown.

So for example, whenever the value is going from 21 → 20, 41 → 40, 61 → 60, and so on (I’m making these up, I don’t know the right thresholds), you want to assign the keystroke/command set in the Dynamic Property trait for decrementing the value in your Trigger, and design your PME to catch all the right cases, then perform the keystroke in the Layer trait that shows the next image down.

Trigger when properties match {morale_value =~ 20|40|60|80|100}
Key command: command for Dynamic Property decrement goes here
Perform: command for lowering image level of Layer trait goes here

Same concept for when the values are doing up. This isn’t adjusting Layers exactly, but shows the idea in one of my modules. Whenever Ctrl+P is spotted (which increases the value of the property ProtestantSpaces) and the new value is any of these specified values, a bunch of stuff happens in response.

After some quick tests.
It worked with the following settings :

The critical part which I was missing until now was to put the key command that actually drives the dynamic property down. I used to put a random name as I did with everything else since the begining.
With the proper name it works.
Though, I have at least 15 entries in that dynamic property each one with its own modifier to to morale value, then I will need to work on that now.

OK I think I’m getting the idea. I also have absolutely no clue about the existence of the =~ syntax, I don’t really know what that is but I guess here that it is sort of a == but applied to an ‘array’ a value ?
If that’s the case that would be great 'cause if I need 15 different triggers with each one carrying one of the 15 possible key commands (provided they must be different) TIMES all of the possibilities with the PME… that would be huge.

I cannot thank you enough !

Check out the Expressions help page. If you want to check equality against a variety of values, you can use =~ and give it a pipe-separated list like I showed. I don’t think you’re going to need anything other than 2 commands in your Dynamic Property–one for increment, one for decrement. Then 2 Triggers–one for going up past the qualifying thresholds, one for going down.

Thanks !
My increase/decrease of morale_value are not ‘one by one’ they are more ‘jumps’ (+10, -15, etc…) so the =~ might not work if I understand it right.
But I think this could be worked out anyway by increasing the number of triggers…

Hi again,
It’s done ! Everything works !
I even managed to make my percentage thing happen. I was using a marker INSIDE the prototype though so there might be some more tweaking to do so that the morale system can use the starting value from elsewhere but anyway…
Thank you very much for your help !

1 Like