|
String to integer using javascriptOkay I ran into an interesting scenario trying to sort through an xml feed. The Structure I have has a number of completes field and Im trying to get a leaderboard set up with the top completes displayed but the feed has the completes as a string and as such the structure sort sorts them alphabetically. Meaning that 10 would actually come before 2 which can cause some major issues in sorting. I found that if I use a number splitter off the complete index and rebuild the structure w/ the kineme structure maker then sorting works but the structure Im using can range to over 400 members so manually doing this is out of the question and i don't think iterator is the answer. Can anyone assist me in a javascript answer on how to change a substructure in an entire structure list from a string to an integer? Or even simpler, tell me if Im missing something in the structure sort?
|
I've attached a sample composition to further exemplify My issues. In my actual comp im sorting a substructure but this gets the point accross.
This is one way to approach it; you take the structure, iterate it while converting with one splitter, rebuild the structure, then publish the output.
...it will only work in SL though.
I've tried the iterator queue technique you provided gtoledo3 but i noticed the fps drops to 12 from 59. Im iterating through 300+structures... its a work around and thank you for that. Hopefully we can find some other means of doing this.
this is how to cast a string to an int in javascript.
The problem with that is that it does the same thing as converting with an insert splitter, effectively (probably takes more time.. I'd be curious to profile it).
It's a structure of strings, that then needs to be converted to a structure of numbers.
Hmm, sorry to hear that the published out with the iterator is so slow for you - I've had it run pretty well, but each scenario is different... the main reason I came up with that was for structure smoothing, not conversion (you could place a smooth in there and it would work fine).
You've got me curious...
RE: Javascript: In simple cases the casting gets done automatically just by setting the output type to number.
Inside an array you need to use the parseInt or some other method like Dust said.
Oh, that made sense ... cool. I wonder how quick it will work, speed wise.
n/a fps!
For some things I find the Javascript patch is unnoticeably fast, as long as it doesn't have to loop toooo much. Crank 'size' up to 10000 numbers and you notice it being slow though in this comp. But for sorting 1000 numbers it's pretty much instantaneous eben on my old beast.
i find using the qc structure sort very fast to make a leader board.
Apple should really sort out the ordering confusion that exists with
<QC_Structures>
and item numbers and "n" key numbers when generating structures with JS patch. I've been going around and around in circles trying to write JS patches that unscramble these disordered structures. It's doing my head in and is a big time PITA!what is a qc structure really ? NSDictionary? NSAray? Structure to file saves a .plist
Not sure NSDictionary aren't they(?!). I've heard that the problem is webkit, but smokris was saying it's something he's looking to fix in next version of structure tools too. I've got no idea what the underlying data types are but it seems to have something to do with the issue where you get a list of items and the order the list in the tool tip is different to the number inside the quotes (even when you didn't use a key).
I've been trying various Javascript ways of assigning items from one structure to another. Also sorting with the sort patch which is powerful (but as said in OP it sorts by alphanumeric not Float when comparing numbers so 72 is sorted before 8).
I've been messing around and even declaring
a = new Array()
gives a different structure toa = new Object
even if all the other code is identical.Here's a comp that makes comparing a little easier. Interesting to try different ways of assigning values in JS patch that generates the structures too like backwards counting of "Char" item etc...
It can be an array, or a dictionary. I would try something like:
result.Input = new Array();
... to get a correctly ordered array when writing to file . "Inside" QC, this seldom matters.