PROCESSING EMPTY RETURN FROM DIALOG
Objective:
Set dialog output to a default when returning nothing.
The issue:
Dialog does not output anything if the field is empty on return, except the prefix ‘symbol’ (outputmode 0).
Proposed solution:
Split the dialog output, store the right list in zl.reg and run the left list through zl.len. Output the default if 1 (no data), else pop the register and strip the prefix on the way to output.
Complication:
When dialog returns the prefix ’symbol’ without data, zl.len counts the length as 2, even though whatever-2nd-element is hidden from mortal eyes. It also counts it as 2 when there IS one data element, or higher of course if there are multiple data elements.
Remarkable, what?
The voodoo:
Feed the output from dialog to a tosymbol and immediately fromsymbol it back before the split. This removes the whatever-2nd-element and the count will be true.
That's a fun one! I think [dialog] should definitely just output "symbol" with no extra symbol when the text field is empty.
What's weird also is that sending the [dialog] output to a [tosymbol] and then to [atoi] reveals that the space is just a regular space (32). However, sending the output to a [route "symbol "] doesn't match, but a [string.compare "symbol "] does.
So here's my version:
you could also utilize the key object to bind and action to the return key. which is only executed when dialog does not return anything in the next 25 ms.
Instead of the tosymbol/fromsymbol pair, you can use [regexp " " @substitute]. That will strip the space. It remains curious that zl.len counts the space as an element.
The regexp solution does not work well. I'll stick to the to&fromsymbol pair.