Reverse the Sort table HELP!
 

News:

29 December 2022 - PtokaX 0.5.3.0 (20th anniversary edition) released...
11 April 2017 - PtokaX 0.5.2.2 released...
8 April 2015 Anti child and anti pedo pr0n scripts are not allowed anymore on this board!
28 September 2015 - PtokaX 0.5.2.1 for Windows 10 IoT released...
3 September 2015 - PtokaX 0.5.2.1 released...
16 August 2015 - PtokaX 0.5.2.0 released...
1 August 2015 - Crowdfunding for ADC protocol support in PtokaX ended. Clearly nobody want ADC support...
30 June 2015 - PtokaX 0.5.1.0 released...
30 April 2015 Crowdfunding for ADC protocol support in PtokaX
26 April 2015 New support hub!
20 February 2015 - PtokaX 0.5.0.3 released...
13 April 2014 - PtokaX 0.5.0.2 released...
23 March 2014 - PtokaX testing version 0.5.0.1 build 454 is available.
04 March 2014 - PtokaX.org sites were temporary down because of DDOS attacks and issues with hosting service provider.

Main Menu

Reverse the Sort table HELP!

Started by NightLitch, 03 February, 2004, 00:17:12

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

NightLitch

hey guys!  How do I make this function so it sorts from
high to low ??

this is from low to high.

function TopKicks(curUser,data)
	local Msg = "\r\n"
	Msg = Msg .. "\r\n       TOP Kickers "
	Msg = Msg .. "\r\n -----=============================================================--- "
	local temp = {}
	local count = ""
	local nick = ""
	for n, num in TopKickers do
		tinsert(temp, num)
		nick = n
	end
	sort(temp)
	for i=1,getn(temp) do 
		local _,_,vCount = strfind(temp[i],"(%S+)")
		Msg = Msg.."\r\n      "..i..".  "..vCount.."   "..nick..""
--		count = i
	end
	Msg = Msg .. "\r\n "
--	Msg = Msg .. "\r\n       Total Users Online: "..count..""
	Msg = Msg .. "\r\n -----=============================================================--- "
	curUser:SD(BotName,Msg)
end

plz help me out.
//NL

[NL]Pur

maby a wild idea but i think the sort function is the one you need too reverse

NightLitch

#2
Yes but how... Hopping you all have some good explainings &
solves tomorrow. Gonna sleep now.

Plz help me out.

And one other thing. I don't seam to get the right name
with right number.

Getting same name on everyone.

/ThX
//NL

c h i l l a

local nick = ""
for n, num in TopKickers do
tinsert(temp, num)
nick = n
end
sort(temp)
for i=1,getn(temp) do
local _,_,vCount = strfind(temp,"(%S+)")
Msg = Msg.."\r\n      "..i..".  "..vCount.."   "..nick..""
--count = i
end
Msg = Msg .. "\r\n "

well...  I am no good explainer, but...
you do nick = n, well okey then nick will be you last n form for n,num in....  you run through the whole table...
so what do you need, you also need to insert the into your temp table. either as string or staright as a table..

I'll just give you the code..

for n, num in TopKickers do
tinsert(temp, { num,n })
end

sorting

sort(temp, function(a,b)  rerutn(a[1] > b[1]) end)

hm...  I don#t get this part, but if you need the strfind to get the number, well.. then
for i=1,getn(temp) do
local _,_,vCount = strfind(temp[1],"(%S+)")
Msg = Msg.."\r\n      "..i..".  "..vCount.."   "..temp[2]..""
end

plop

if sort shows it from low 2 high all you gotta do is walk thru it in reverse.
for i=getn(temp),1 do

plop
http://www.plop.nl lua scripts/howto\'s.
http://www.thegoldenangel.net
http://www.vikingshub.com
http://www.lua.org

>>----> he who fights hatred with hatred, drives the spreading of hatred <----<<

c h i l l a

have you ever tried your func.
only way to do what you want is to do like
for i = -(getn(temp)),-1 do
i = i*-1
end

tezlo

for i = getn(tmp), 1, -1 do ..

c h i l l a

#7
its the same.
but well there are many ways.
when I think of it, even more...

can you also do in a nicer way

for i = -(getn(temp)),-1 do
i = i*-2
end

tezlo

you shouldnt change i inside the block.. why complicate it anyway?

c h i l l a

#9
So is there another way? I guess not,
well if I should have problems then i'll just create another variable.

tezlo

lua has its own way.. what i just posted
for i = getn(tmp), 1, -1 do ..

c h i l l a

QuoteOriginally posted by c h i l l a
its the same.
but well there are many ways.
when I think of it, even more...

can you also do in a nicer way

for i = -(getn(temp)),-1 do
i = i*-2
end

???

NightLitch

Thx alot guys for helping me out on this, learn a few new things again.

final code:
function TopKicks(curUser,data)
	local Msg = "\r\n"
	Msg = Msg .. "\r\n       TOP Kickers "
	Msg = Msg .. "\r\n -----=============================================================--- "
	Msg = Msg .. "\r\n        Rank	Kicks		Nicks"
	Msg = Msg .. "\r\n        ?????	?????		?????"
	local temp = {}
	for n, num in TopKickers do 
		tinsert(temp, { num,n }) 
	end

	sort(temp, function(a,b) return(a[1] > b[1]) end) 

	for i=1,getn(temp) do 

	Msg = Msg .. "\r\n           "..i..".		"..temp[i][1].."    		"..temp[i][2].."" 
	end
	Msg = Msg .. "\r\n "
	Msg = Msg .. "\r\n -----=============================================================--- "
	curUser:SD(BotName,Msg)
end

How Do I make a total count over the kicks ??? can't seam to get that thing right either.

ThX guys you're the best.

/NL
//NL

plop

QuoteOriginally posted by tezlo
for i = getn(tmp), 1, -1 do ..
whoeps your right, forgot the ,-1.

plop
http://www.plop.nl lua scripts/howto\'s.
http://www.thegoldenangel.net
http://www.vikingshub.com
http://www.lua.org

>>----> he who fights hatred with hatred, drives the spreading of hatred <----<<

NightLitch

Plop you showed me for a time ago How to "add" values togheter and getting one how did I do that now again.

plz help.
//NL

NightLitch

There's no need helping me more here solved it.
//NL

VidFamne

Please post the solution, so everybody in here can take benefits from it.

NightLitch

sure no prob.

function TopKicks(curUser,data)
	local Msg = "\r\n"
	Msg = Msg .. "\r\n       TOP Kickers "
	Msg = Msg .. "\r\n -----=============================================================--- "
	Msg = Msg .. "\r\n        Rank	Kicks		Nicks"
	Msg = Msg .. "\r\n        ?????	?????		?????"
	local temp = {}
	local count = 0
	local you = ""
	for n, num in TopKickers do 
		tinsert(temp, { num,n })
		count = count + num
	end

	sort(temp, function(a,b) return(a[1] > b[1]) end) 

	for i=1,getn(temp) do
	if curUser.sName == temp[i][2] then
	you = "\r\n        --------------------------------------------------------------------------------------------------------------\r\n"
	else
	end
	Msg = Msg .. "\r\n"..you.."           "..i..".		"..temp[i][1].."    		"..temp[i][2].." "..you..""
	if you then
	you = ""
	end

	end
	Msg = Msg .. "\r\n "
	Msg = Msg .. "\r\n       Total: "..count.." kick(s)"
	Msg = Msg .. "\r\n -----=============================================================--- "
	curUser:SD(BotName,Msg)
end
//NL

plop

QuoteOriginally posted by NightLitch
Plop you showed me for a time ago How to "add" values togheter and getting one how did I do that now again.

plz help.
don't ask so soon, i knew you could do it. lol
naaa was busy on other things, trying 2 learn lua 5.0.
but if you want a quick answer, pm me in my hub with the url.

plop
http://www.plop.nl lua scripts/howto\'s.
http://www.thegoldenangel.net
http://www.vikingshub.com
http://www.lua.org

>>----> he who fights hatred with hatred, drives the spreading of hatred <----<<

c h i l l a

what is faster

i = 1,10^6,100

or i = 1,10^4
i = i*100

what about
i = 1,8
i = i^3

can this be done more nicely?

SMF spam blocked by CleanTalk