Why does variable array notation show in red in Variable fields?

I'm referencing the first line of a multi-line line-break-delimited text field in a Variable field:

image

But why is it red? The Variable Arrays wiki page doesn't say anything about red text. Now, I think I know why it's red, as noted on the Text Fields wiki page:

If the function is invalid, it will highlight in red. Keep in mind that the expression may be invalid simply because a variable it references does not yet have a value.

So I assume this is Keyboard Maestro telling me it can't get the value of that line of the array value…but the red makes it look like this will fail. But it works fine, of course.

At a minimum, the Variable Arrays wiki page should probably mention that "red text is OK in this instance," but personally, I don't think it should be red if given it's an allowed construct. Is this a "just me" thing? :slight_smile:

-rob.

I think red means "I can't evaluate this right now." Personally, I don't see any problem in that being the meaning of red. In your case, the only reason it can't be evaluated is that the variable is an Instance variable.

To be honest, I never knew you could use indexing when a field required a variable. Thanks for the tip.

instance_theMacroPost[1]\n

That's not a name that references a variable.

(It's a textual expression which, in a KM text field, can be processed to derive a string value)


Only instance_theMacroPost is the name of a variable.


To put it another way, the existence of variable arrays does not imply that of "array variables".

2 Likes

Does it? Have you an example? Because this:

Array Test 2.kmmacros (10.2 KB)

Image

...suggests you can't.

Note: If you test the above, make sure you change the first "If" action's Local_text to Local_text[1]\n -- exporting the macro deletes the "invalid" characters.

AFAIK you can only use custom array delimiters in text tokens.

1 Like

Thanks, though it still bugs me that they're red, as they stop my eye every ... single ... time :).

-rob.

A syntax error and a type error.

It should stop you writing that kind of thing :slight_smile:

I thought it did…but it was late last night and I'd been fighting SQL and KM for hours ... testing again this morning, "umm, never mind." Moderators, get this man a vacation. Readers, ignore this topic :).

-rob.

1 Like

Exactly, it's a textual notation which text fields can resolve to a string value.

1 Like