|
| 06 Oct 2016 11:28 AM |
--This script i made can sort tables by their keys alphabetically and reverse alphabetical, also numerically.
--It can also sort them by VALUES! Numerically and alphabetically as well. It allows you to sort them using PATHS where you can sort them by their parts such as players by their kills or items like weapons by their price.
In case it gets hashtagged i have uploaded it to pastebin, enjoy! It comes with examples so be sure to run them if you want to check.
http:// pastebin. com/ jg6c Sk60 |
|
|
| Report Abuse |
|
|
|
| 06 Oct 2016 11:30 AM |
| Sorry for posting on my alt here but enjoy my code |
|
|
| Report Abuse |
|
|
|
| 06 Oct 2016 11:34 AM |
It returns the key,value,order
order is just the order of the item in the list |
|
|
| Report Abuse |
|
|
|
| 06 Oct 2016 11:56 AM |
| has a slight bug with unicodes like the ___ |
|
|
| Report Abuse |
|
|
| |
|
|
| 06 Oct 2016 01:11 PM |
waiting for people to realize this is useful
like sortinf players in a leaderboard by their ranks or kills or whatever |
|
|
| Report Abuse |
|
|
|
| 06 Oct 2016 01:12 PM |
Interesting piece of code. I don't have an intentional use for this, but I'm sure others will.
( ͡• ◡ ͡•) -=[ RAP: 414,345 || DurstAuric; the narb of ROBLOX ]=- ( ͡• ◡ ͡•) |
|
|
| Report Abuse |
|
|
|
| 06 Oct 2016 01:14 PM |
run it in your console or command bar or any lua program
you can look around at the code to see what it does and what it can be used for
especially the spairsval with paths
you can even sort things by their properties and the path can be as long as you want, works on objects too |
|
|
| Report Abuse |
|
|
|
| 06 Oct 2016 01:19 PM |
| calling either spairs may make performance a bit slow though but you could use a coroutine if calling it really matters (which might not) |
|
|
| Report Abuse |
|
|
|
| 06 Oct 2016 01:20 PM |
| the iterating function it returns should not be slow though which is nice. have fun using this though, might be useful some day |
|
|
| Report Abuse |
|
|
| |
|
|
| 06 Oct 2016 11:12 PM |
trying to find out how to make a next function that returns the key at a certain index
(example:)
test = { a = "aval"; b = "bval"; }
pos(test,1) --should be a,aval because it is the first item pos(test,2) --should be b,bval because it is the 2nd item |
|
|
| Report Abuse |
|
|
|
| 06 Oct 2016 11:14 PM |
without having to do this i mean
function pos(t,n) local p = 1 for k,v in next,t do if p==n then return k,v end p = p+1 end return nil end |
|
|
| Report Abuse |
|
|
KreoBox
|
  |
| Joined: 24 Aug 2016 |
| Total Posts: 356 |
|
|
| 07 Oct 2016 03:48 AM |
| You do know that non-array tables have no order right? You can't sort them. |
|
|
| Report Abuse |
|
|
|
| 07 Oct 2016 07:00 AM |
what the hell just get a script from crapoverflow
https://www.roblox.com/library/322704057/Hillary-Clinton |
|
|
| Report Abuse |
|
|
|
| 07 Oct 2016 07:04 AM |
Nevermind
https://www.roblox.com/library/499105467/Hillary |
|
|
| Report Abuse |
|
|
|
| 07 Oct 2016 08:46 AM |
| Stop over-rating your script, I can't think of any _real_ practical use for this of why anyone would actually need it. |
|
|
| Report Abuse |
|
|
|
| 07 Oct 2016 12:30 PM |
| Dictionaries are sorted, when you call next, it iterates in the order the items of the table were added |
|
|
| Report Abuse |
|
|
|
| 07 Oct 2016 12:31 PM |
it sorted it in an araay : )
but anyways it still acts like it sorts dictionaries which is nice |
|
|
| Report Abuse |
|
|
KreoBox
|
  |
| Joined: 24 Aug 2016 |
| Total Posts: 356 |
|
|
| 07 Oct 2016 12:50 PM |
"Dictionaries are sorted, when you call next, it iterates in the order the items of the table were added"
You are really, really stupid. The order next enumerates through the table is not specified.
In case you didn't notice, you get the value from a specific key, said key-value pair is not related to any other such pair. |
|
|
| Report Abuse |
|
|
|
| 07 Oct 2016 12:53 PM |
fine but still it iterates through dictionaries and arrays alphabetically sorted fashion and also you can still iterate through things like kills of each player without having to always make a path to it |
|
|
| Report Abuse |
|
|
|
| 07 Oct 2016 01:56 PM |
what? "iterate through things like kills of each player without having to always make a path to it" that doesn't even make sense
go home |
|
|
| Report Abuse |
|
|
|
| 07 Oct 2016 02:00 PM |
Yes it does
Use spairsval flux and stop complaining
local players = { Player1 = { leaderstats = { Kills = { Value = 29; } } }; Player2 = { leaderstats = { Kills = { Value = 2129; } } }; } --this is an example layout
for pl,player in next,players do print(pl,player.leaderstats.Kills.Value) end
for player,kills in spairsval(players,true,"leaderstats","Kills","Value") do print(player,kills) end |
|
|
| Report Abuse |
|
|
|
| 07 Oct 2016 02:02 PM |
Yeah and the bottom method is horrible and disgusting. You don't know how to create useful iterators. |
|
|
| Report Abuse |
|
|
|
| 07 Oct 2016 02:03 PM |
so? its still a different way to iterate
no one cares about your 'this is bad' crap because at least it has a purpose |
|
|
| Report Abuse |
|
|