How do you test for a null message or symbol?
I am importing data that I don't create, and I need to be able to test if a message or symbol is null.
I am basically importing json data using dict - and when querying the value of one of the keys I want to check if the key contains a null string : ""
Am I missing something simple? I have searched for a while now, and can't seem to find any ideas. How do I do this?
I've been in your situation many times and have come up with 2 strategies :
1) I now do most of my dict processing using Javascript, where it's easy to do something like:
var val = myDict.get(somekey);
if ((val == "") || (val ==" undefined")) {
//empty/null string found, do stuff
}
2) if working with just patching, you can use a similar setup as with testing for "no output". Something like this:
Have the get message to the dict first set a [message] to "nothing", the the output value of get goes thru [t b s], s goes to the [message] 's right inlet, bang to the left. The [message] goes to [route nothing] which then gives you a bang out the left for an empty string and everything else out the right.
I'm on my phone, sorry I can't post a patch. Hope this is all coherent/useful/correct :)
Turns out it seems there is a secret... if you use a [route ""] object, route will bang on empty message. It seems you actually have to enter the double quotes as the parameter to route in order for this to work. You can't just use [route]. Here is a sample patch.
Uhgg... I don't think its working. It seems like whenever I save the patch and then reload it the [route ""] object gets changed into a [route] object and it stops working.
So now I am stuck again... There has got to be a way to test for an empty (null) message, right?
hmm. maybe...
Hi lightspeed.johnny,
while the easiest way to dict handling is with JavaScript, here is a way to do what you want with patching.
Nick.
Oh yeah.. in terms of your ultimate goal..
Wow Metamax - that regex solution is pretty dang clever - and it seems to be working for my use-case.
Nikolas - didn't know about [fromsymbol]... That's the thing I love about Max - there is (almost) always a way to do what you want to do... however, it is not always the most intuitive way... why cant we just do something like [==null] - a special object that tests against null or empty symbols . There has to be a better way at handling empty messages.... and yeah, I understand that javascript has much better equality functions (though you really have to be careful about == vs ===) - I spend my days writing a lot of javascript - it just so happens that in this one case, all I wanted was to test for an empty message and I didn't think I needed js for that :)
Yeah, I figured out that there is no way to clear the data in an fpic once it has been set, and you have to use "hidden 1" and "hidden 0". I really think that fpic should have a "clear" message that it responds to which basically resets it to its initial state.
I am also learning that fpic leaves a lot to be desired - especially in regards to image cropping and justification. But, I am sure the C74 feature request list is monstrous as is.
Wow indeed, metamax's solution is far more elegant, I am almost jealous!
As for the "null" checking, I do understand the need for it across the environment, but I also think that Max's graphical environment diverges from the "coding" mentality. As I understand, it is meant a bit to "just work"! Make an object, "bang" goes in, result goes out, "cable" here, "cable" there, simple!! You don't need to know what a "null" variable is.
But there is a need for lower level coding, and is (somewhat) covered in the JS and Gen environments, where you are excepted to know your stuff!
Anyway, I am probably getting carried away over a "null" comparison! Good luck with the project!
Nick
[select "<empty>"] is working for me. Cheers.
[select "<empty>"] is working for me.
I guess you mean typing [select ""] when instanciating the object.
It works until you save your patch, close it and re-open it.
Then it doesn't work anymore, because the empty string arguments got discarded and the corresponding inlets and outlets disappeared.
FWIW, I found this trick for use with [select] and [route] :
Wouldn’t it be great if, when you bang an empty message, it would output a NULL? That would solve a whole lot of problems!
But it doesn’t, so one has to use a work-around. Here’s one:
A dump from a register of my synth produces 24 SysEx messages (0xF0…0xF7).
The first and last one of these contain no data bytes, just the header and a checksum - an ACK and an END, effectively.
I want to store all 24 of them, including ACK and END, in a coll, but only the actual data.
My SysEx parsing routine extracts the data, the byte count, the base address and the checksum.
If the byte count is 0, there are no data and its entry in coll would contain no data either.
This would cause problems downstream; something has to be filled in to indicate ‘no data’.
Below a routine to accomplish this based on the byte count, using 0xFF as the filler.
When I need an empty symbol, I send a number to a [t s]. To match it in [sel] or [route], I put in the empty sym with a loadbang.
