Finding Names in Objects
-
Hey!
Let me give you a background on what I'm doing, if you don't want to read it, then go to the word
THANKS
. In the player i'm creating, it runs off of three samplers and you can mix and match samplemaps of those samplers from all samplemaps you've obtained through multiple instruments. Now to select these sample maps, I'm creating this layer browser consisting of this:There's two viewports with a label (for searching the second viewport) and a current layer(samplemap) panel. Now since the samplemaps are spread across multiple expansions, i'm planing on running a script in each expansion which adds the samplemaps to a respective "tag" (which is what goes in the first viewport) and when the tag is clicked on in the first viewport, the samplemap names show up in the second viewport.
THANKS
I'm planning on doing this by making an object and making it almost like a filesystem in case. There'll be objects in the objects acting as directories of the previous object. For example, here's a test object which would show what my thought is:reg layerScreenObject = { "All": { "Bionic Morph": { "instrument": "Night Owl" }, "Native Morph": { "instrument": "Night Owl" }, "Plucked Morph": { "instrument": "Night Owl" }, "Test Morph 1": { "instrument": "Example" }, "Test Morph 2": { "instrument": "Example" }, "Test Morph 3": { "instrument": "Example" } }, "Pad": { "Bionic Morph": { "instrument": "Night Owl" }, "Test Morph 1": { "instrument": "Example" } }, "Chord": { "Native Morph": { "instrument": "Night Owl" }, "Test Morph 2": { "instrument": "Example" } }, "Pluck": { "Plucked Morph": { "instrument": "Night Owl" }, "Test Morph 3": { "instrument": "Example" } } };
As you can see, the "tags" are
All, Pad, Chord, Pluck
and I want to show these in the first viewport. In each of these "tag" objects, there's an additional object which represents the samplemap. The names of the object would be going into the viewports. Quesiton is, how do I make this happen? I tried tracing, but it shows the whole contents, I just want to get the key of the first level objects inlayerScreenObject
(All, Pad, Chord, Pluck).THANKS
! Probably a lot of unecessary info haha! -
@Casmat for in loops are probably what you need
-
var obj = { "someEntry": [1, 2, 3, 4], "someOtherStuff": "yes" }; for(key in obj) { Console.print(key); // someEntry, otherStuff Console.print(trace(obj[key])); // [1, 2, 3, 4], "yes" }
-
@d-healey @Christoph-Hart haha! I had tried a for loop but it had returned an undefined error, mustve been a type error on my part since it works now! Thanks again!
-
@d-healey @Christoph-Hart Oops, another thing popped up. I've put each of those objects into an array, but I can't sort them since they're objects. How do i take that object name ("All", "Pad", "Chord", "Pluck") and make it a string so it is sortable and presentable in a viewport? I thought of putting a value in the object something like this
"name": "All"
but is there an easier way to convert it? -
Anyone know?
Thanks!
-
@Casmat Nested loops are what you use to access the inner elements
-
@d-healey Could you please give an example? I’m sorry, didn’t fully understand how I should use nested loops to get the names of the objects
Edit: or are you saying that I should use
”name”: “All”
alongside nested loops?Thanks!
-
Have you seen this video?
https://www.youtube.com/watch?v=orqzckIOy0E
If you give me a simple snippet that has the object/arrays setup and tell me what you want the output to be I can give a more specific answer.
-
@d-healey Yup, watched the video! Basically, the object
layerScreenObject
(first post) is what the question is based around. In the object you can see that there’s multiple objects (All, Pad, Chord, Pluck). In each of those objects, there’s more objects which have the different “Morphs” (SampleMaps). All I want to do is get the first-level objects (All, Pad, Chord, Pluck) and turn them into strings. I don’t want to trace them and get the contents, just the objectAll -> “All”
. So basically, the output should result in a new array with the following values:[“All”, “Pad”, “Chord”, “Pluck”]
. Really, I’m trying to makelayerScreenObject
act as a makeshift file system with each of the objects being “directories”. The data, such as”instrument”: “Example”
are the “files”. This is all so I can make a browser which searches the samplemaps and divides them up into different categories such as pad, chord, pluck with “All” being all the samplemaps. Can’t currently send a snippet since my computers going through a long update, but hope this info clarifies!Thanks!
-
@d-healey Ok, just retried it all from scratch and now it works. I guess my eyes were playing tricks on me the whole time haha. I had thought for some reason that when you push each of the objects inside an object into an array, the objects would be inside the array, but apparently, when the push function is used, the object's name is converted to a sting. Sorry for the major confusion!
HiseSnippet 1001.3ocsV01aaaCDlzwZnVaYXsn66B5S1.YF18sMzfg4FGmAi033MmELfstNFoyVrlhTfhJoFCAX+c1+t8OX6njeQtwoHwqUeR2KO7d3Qd2wgZU.jlpzDZsSmk.D5m4LZlzD0Mhwkj9GRn65bFnS6FAASAM4fYIrzTHjPo678VWn0pRx+9mu6.lfICfUpHjyT7.3k7XtYk1gc9AtPbDKDNkGWx6mzoefR1UITYHc1woEIgELkMAFvrtUwgP+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