Using "obj"
-
When I search on "obj" in the Docs I don't get any hits.
I have only picked up so far what to do with it in context (obj.value, obj.over etc.).
Does "obj" itself return the component ID? Or do I have to do anything special to get it?
I am doing some LAF right now and I'm trying to make conditions based on the component ID. -
@VirtualVirgin
obj
is just the name we give to the object that is passed to a laf function, but it could have any name, so you won't find it in the docs.The contents of
obj
varies between different laf functions, to find out what it contains in the function you're in you can useConsole.print(trace(obj));
You should generally use local laf, so you can assign a separate laf to each component, so you don't need to do things based on the component ID. You can also share a single local laf between multiple components and use the properties of each component within the laf - again avoiding the need to filter based on the ID. But there are some occasions when knowing the ID can be useful.
-
@d-healey Thanks :)
I'm using it to color keys on a keyboard based on a range, so I need the ID of each button (key) component to see if it is in range. The component reference definitions are stored inside an array, so I've got this now:
if(keyboard0.indexOf(obj) >= rangeMin && keyboard0.indexOf(obj) <= rangeMax)
"keyboard0" is an array of the keys indexed in order (0-127).
All of the button keys share the same LAF.
Currently, rangeMin and rangeMax are set to 0/127, but this is not returning "true" and hence does not seem to return the component ID.
-
@d-healey
Ok, so I'm noticing that this method of making script definitions does not get the user ID name into the array, just HISE encoded Object ID:It doesn't respond to searching for the user ID.
If I print the obj.id from the LAF, it is giving me the user ID name, not the encoded Object ID:
So is there a way to convert the user ID name to the HISE encoded one?
I think the mismatch is causing my range conditions to return a false.
-
@VirtualVirgin said in Using "obj":
user ID name to the HISE encoded one?
I'm not sure what you're referring to here. But looking at the bit of script you posted:
Content.getComponent()
will get a reference to the specified component, in the form of a ScriptObject. If you want to view the ID of one of those components you can usemyComponent.getId();
or in your examplekeyboard0[3].getId();
-
@d-healey
I was referring to the difference between the user name for the ID and the one HISE creates "Object 0x58dca420" or whatever it comes up with.
Up until this point I thought putting the script variable definitions in the array was storing the ID name at the indexes, but apparently not.
To solve here I just pushed a new array specifically for the ID names and now it works to match the names with an index, and thus satisfies the condition above and returning "true".Thanks for the help :)
-
@VirtualVirgin said in Using "obj":
I was referring to the difference between the user name for the ID and the one HISE creates "Object 0x58dca420" or whatever it comes up with.
Console.print
will only display text. When you pass it something that isn't text it will display what it is, Object, Array, etc. In the case of objects it also prints some hex numbers which I'm not entirely sure what they are, perhaps a memory address, either way the information is not useful to us.