![]() |
Sorting
Im trying to grab values from a dbnpc and sort them out.
The names are under this.names.NAMEHERE. I also need to pull this.names.NAMEHERE.kills. What I'm looking to do is sort the .kills from highest to lowest, pull that with the NAMEHERE, and pull only the top 5 from the sort. So it would look like: NAMEHERE 50kills NAMEHERE 43kills NAMEHERE 5kills so on and so on. I found TGraalVar.sortbyvalue(str, str, bool), but can't seem to get it to work with this. Is there a better way? How do I go about this and with what commands? I really wish graal.net was up. :( |
|
I know you can do something like
PHP Code:
Quote:
Quote:
|
I know SQLight is the way to go, but we've already got so much wrapped around this dbnpc id rather not change it all.
Now on this: PHP Code:
PHP Code:
PHP Code:
PHP Code:
|
Quote:
Note that the optimizer can only make use of an index on the ORDER BY if it is a composite index covering all the WHERE conditions and ORDER BY conditions. e.x., PHP Code:
e.x., PHP Code:
The overhead of talking to SQLite and the overhead within the engine also certainly need to be taken into account when doing something small, where it often makes things faster to just manipulate the data in GS2. |
Quote:
|
Chompy is right. SQLite is more of a convenient, centralized way to store lots of data, it's not wise to use it just for sorting capabilities.
You just can't go wrong with quicksort. :] |
Quote:
Quote:
|
Well here's a little example on how to use sortbyvalue, it seems tricky due to the lack of documentation but it's quite simple overall. (Didn't see cbk posted this already but oh well..)
The syntax provided by script help, edited for clarity. (On RC: /scripthelp sortbyvalue). TGraalVar.sortbyvalue(str1, str2, boolean) - sorts an array. str1: the variable of the array members which is compared str2: variable type; variable type can be "string", otherwise it is sorted by floating point value boolean: sort by ascending (I.e: 1 to 9) or not Usage: PHP Code:
PHP Code:
|
Ok, ive got it working when it echos in the rc, but having problems showing it up in the gui.
I have this in a weapon, under clientside. Ill only be posted whats appropriate to the code needed. PHP Code:
PHP Code:
PHP Code:
PHP Code:
|
Also, just to note, if i stick the "return" inside the for loop, it comes out with no value in the gui, but I can echo it in the for loop and in rc its perfectly fine.
e.g. PHP Code:
|
My problem still isnt fixed. now its only showing the first this.guilds.guildname.kills value, and not the others in the gui.
PHP Code:
|
I don't think you understand what's going on, when you use sortbyvalue, added comments to show what's going on.
PHP Code:
|
I know I dont understand it. Trying to. :(
This is what I got now. PHP Code:
PHP Code:
Also tried temp.g.kills like in ur last example, did the exact same thing. I get the concept, pull all guild names, run those to pull all kills, sort guild names, display. Its just not workin for me. :/ |
Could you provide the test data that you are using? I've been showing you examples based on your posts and how I think the data is stored.
Also you specified true as the ascending sort boolean parameter so it's putting the guild with the least kills at the start of the array, which could be the cause of the "random" results. |
All times are GMT +2. The time now is 01:47 AM. |
Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.