how to access unique dictionary in m4l?

11OLSEN's icon

nabend, can i access a dictionary from my external that i made unique for a certain m4l device with the 3 hyphen name?

i don't even try this.
t_dictionary *foo = dictobj_findregistered_retain(gensym("---test"));

11OLSEN's icon

i think i will just create a dictionary with device id in name at device init and pass the name to the external.

do.while's icon

hello !
i dont know any other way than u just figured . passing as an argument onto your external would do the job for the init stage . if there is another way , i would love to know

Julien Bayle's icon

For the record, a trick:

Use a scripting name. This one is persistent and local to the device instance.

Instead of trying to "guess" or "inject" the resolved name from the outside, you let the JS (or external) ask the patcher for the name of the object it's looking at.

  • Give your dict ---myDict a Scripting Name in the inspector (e.g., theDict).

  • In your JS code, use the following logic to retrieve the real, resolved name (the one with the unique ID like 069...):

// works in M4L even if multiple instances are running
function get_unique_dict_name() {
    var obj = this.patcher.getnamed("theDict"); // The Scripting Name
    if (obj) {
        // This returns the actual name resolved by Live (e.g., "069myDict")
        return obj.getattr("name"); 
    }
    return "---myDict"; // Fallback
}

// Then use it as usual:
var myDict = new Dict(get_unique_dict_name());
TFL's icon

If you already know the naming pattern, no need for that scripting name trick! You can pass ---myDict as a jsargument, and retrieve it from your code directly

If using [v8] or [js], declare your object as [v8 myFile.js ---myDict] and retrieve using jsarguments[1] . If using @embed 1, you need to pass a dummy filename for this to work, like such: [v8 ignore_me ---myDict @embed 1]

If using v8.codebox, put ---myDict in the jsarguments attribute of the object, and retrieve using jsarguments[0]

This also works for #0 #1 notation!

Essentially, more or less the same as suggested by DO.WHILE for externals: pass the name as an argument.