What am I doing wrong? Variable token red

What's wrong with this?

Am I not allowed to reference a variable this way?

Thanks & cheers --Mike

My understanding is that KM variables are treated differently in text fields (where the %Variable%VariableName% nomenclature is used) and calculation fields, where only the variable name itself is needed. I believe window dimension fields are the latter, and thus your issue should be able to be resolved by only using mpwidth in the Move and Resize action, like so:

2 Likes

Thanks, gglick! That did the trick. A bit confusing if you ask me.

Cheers --Mike

In a text field, the field is full of arbitrary text. As such, you need some indication that the chunk of data you have included is not text, but should be processed in to something else. That is what the % character does, and all the text tokens, including the Variable text token are surrounded by percent characters for that reason.

In numeric fields, things are very different, you can only have calculations and valid expressions and functions in a numeric field. So there is no need for a character to mark something as special.

See the Text Fields section on the wiki for more information about this.

2 Likes

Peter, while we don't need the % delimiter in numeric fields, it would be nice if they were allowed. Although it is more typing, it is easier to have only one method for using variables.

Just sayin' :wink:

3 Likes

It’s not inconceivable that I could allow percent encoded tokens in a calculation field.

Not for 8.0 though, I’ll have to ponder the consequences more before a change like that.

1 Like

% in many languages is an arithmetical oprator. :frowning:

Yes, it is often used for Modulo arithmetic, but Keyboard Maestro uses MOD for that.

Keyboard Maestro does use % for, well, percents. So 100% == 1 for example.

But that can only come after an evaluation, whereas a % used for a text token could only come at the start (ie, after an operator), so it may be that the two are not incompatible.

Right. My point In mentioning it is it might be a parser challenge for you.

I’d imagine you’d want to keep your parser "simple ". :slight_smile:

My parser is a lovely recursive descent parser, very nice and easy to maintain. But then I did write an optimising compiler as my uni CS thesis…

1 Like

So let me ask for some really UGLY syntax… :slight_smile:

1 Like