How do you test for a null message or symbol?


    Sep 18 2016 | 5:09 am
    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?

    • Sep 18 2016 | 6:11 am
      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 :)
    • Sep 18 2016 | 7:29 am
      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.
    • Sep 18 2016 | 7:46 am
      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?
    • Sep 18 2016 | 9:07 am
      hmm. maybe...
    • Sep 18 2016 | 9:31 am
      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.
    • Sep 18 2016 | 9:59 am
      Oh yeah.. in terms of your ultimate goal..
    • Sep 18 2016 | 10:20 am
      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 :)
    • Sep 18 2016 | 10:33 am
      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.
    • Sep 18 2016 | 11:38 am
      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
    • May 10 2020 | 7:56 pm
      [select "<empty>"] is working for me. Cheers.