Constant file ID
-
Right, take another look at that code. You only want to dump the JSON after the for loop is finished. At the moment, it's writing a new file with the object every single iteration. You need something more like this. Also be wary, the random ID is a bit deadly because there's always a change you'll get duplicate IDs.
var obj = {}; for (f in files) { var id = parseInt(Math.random()*10000); var p = f.toString(OnlyExtension); obj[id] = p; }; Engine.dumpAsJSON(obj, "../files.xml");
-
@Lunacy-Audio i wan't just test it with this random id, in normal project i'll use letters and numbers to be sure that repeat chance will be really low
-
@Lunacy-Audio unfortunately i still have one object in xml :(
-
This post is deleted! -
@Lunacy-Audio obj outside for should be array :) and then in for loop we push obj to this arr, now i'm curios what's happen when i add new file and what's happen with id
ID chaning everytime.
The worst thing is that the order of the objects is also disturbed.
-
This post is deleted! -
Oops yeah there was a typo in my code. Was accidentally redeclaring the obj.
Yeah, the ID will change every time if you're randomizing it. You need to check whether or not the file already exists in the external JSON and if it does, ignore it and make sure you don't use that ID again. That snippet above is just a really basic example, but you'll need to do some more checks in order to find out which ID to use next and which files have already been stored, etc.
-
Why don‘t you just sort the array of filenames alphabetically? I think the API call has even a parameter for that.
-
Ah nevermind, it hasn‘t. I‘ll add this.
-
I think this method still dosnt make sense because id and file path will be different for every user. :v
-
@Christoph-Hart maybe you have an idea how to do this or its even possible in hise?