Applydeepif: guaranteed retrieval order?

    Javascriptadvanced

    Neil Baldwin
    Apr 26 2023 | 6:24 am
    As per the title really: when using applydeepif() in a patcher to recursively retrieve nested objects in subpatchers, can you be sure of the retrieval order? For example if several objects of the same name were fetched (multiple instances of the same bpatcher contained in a subpatch), could you read/write to those objects in JS in the numerical order they were fetched and be sure you're reading/writing to the correct object?
    If not, how does Max/JS handle (same) named objects inside multiple instances of the same bpatcher?

    • Ali Raza's icon
      Ali Raza
      Apr 26 2023 | 11:59 am
      That’s a very interesting question. According to the Max 8 Documentation, the applydeepif() method of a Patcher object applies a function to all objects in a patcher that satisfy a test function, and recurses into subpatchers (depth first). However, it does not specify the order of retrieval for objects with the same name in different subpatchers. One possible way to handle this situation is to use the box property of the Maxobj object to get the parent object that contains the subpatcher, and then compare its scripting name or position to determine which one comes first. Alternatively, you could use unique names for each object in different subpatchers to avoid confusion
      Share
    • Neil Baldwin's icon
      Neil Baldwin's icon
      Neil Baldwin
      Apr 27 2023 | 4:32 pm
      Thanks Ali.
      It seems indeterminate from testing. I think I'll have to bite the bullet and do some refactoring so that all the things I need to target have unique names, as you say.
      Appreciate the reply though 🙏