generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripters
Home Search
 

Re: Sorted Pairs by key or value

Previous Thread :: Next Thread 
1WithTheNoobiestNoob is not online. 1WithTheNoobiestNoob
Joined: 24 Jun 2012
Total Posts: 145
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
Wunder_Wulfe is not online. Wunder_Wulfe
Joined: 13 Sep 2016
Total Posts: 8356
06 Oct 2016 11:30 AM
Sorry for posting on my alt here but enjoy my code
Report Abuse
Wunder_Wulfe is not online. Wunder_Wulfe
Joined: 13 Sep 2016
Total Posts: 8356
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
Wunder_Wulfe is not online. Wunder_Wulfe
Joined: 13 Sep 2016
Total Posts: 8356
06 Oct 2016 11:56 AM
has a slight bug with unicodes like the ___
Report Abuse
Wunder_Wulfe is not online. Wunder_Wulfe
Joined: 13 Sep 2016
Total Posts: 8356
06 Oct 2016 12:28 PM
bumpio
Report Abuse
Wunder_Wulfe is not online. Wunder_Wulfe
Joined: 13 Sep 2016
Total Posts: 8356
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
DurstAuric is not online. DurstAuric
Joined: 12 May 2009
Total Posts: 8066
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
Wunder_Wulfe is not online. Wunder_Wulfe
Joined: 13 Sep 2016
Total Posts: 8356
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
Wunder_Wulfe is not online. Wunder_Wulfe
Joined: 13 Sep 2016
Total Posts: 8356
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
Wunder_Wulfe is not online. Wunder_Wulfe
Joined: 13 Sep 2016
Total Posts: 8356
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
Wunder_Wulfe is not online. Wunder_Wulfe
Joined: 13 Sep 2016
Total Posts: 8356
06 Oct 2016 10:57 PM
boomp
Report Abuse
Wunder_Wulfe is not online. Wunder_Wulfe
Joined: 13 Sep 2016
Total Posts: 8356
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
Wunder_Wulfe is not online. Wunder_Wulfe
Joined: 13 Sep 2016
Total Posts: 8356
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 is not online. 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
batistapowerbonbtla is not online. batistapowerbonbtla
Joined: 16 Dec 2011
Total Posts: 2203
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
batistapowerbonbtla is not online. batistapowerbonbtla
Joined: 16 Dec 2011
Total Posts: 2203
07 Oct 2016 07:04 AM
Nevermind

https://www.roblox.com/library/499105467/Hillary
Report Abuse
Flux_Capacitor is not online. Flux_Capacitor
Joined: 07 Apr 2008
Total Posts: 45720
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
Wunder_Wulfe is not online. Wunder_Wulfe
Joined: 13 Sep 2016
Total Posts: 8356
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
Wunder_Wulfe is not online. Wunder_Wulfe
Joined: 13 Sep 2016
Total Posts: 8356
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 is not online. 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
Wunder_Wulfe is not online. Wunder_Wulfe
Joined: 13 Sep 2016
Total Posts: 8356
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
Flux_Capacitor is not online. Flux_Capacitor
Joined: 07 Apr 2008
Total Posts: 45720
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
Wunder_Wulfe is not online. Wunder_Wulfe
Joined: 13 Sep 2016
Total Posts: 8356
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
Flux_Capacitor is not online. Flux_Capacitor
Joined: 07 Apr 2008
Total Posts: 45720
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
Wunder_Wulfe is not online. Wunder_Wulfe
Joined: 13 Sep 2016
Total Posts: 8356
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
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image