PtokaX forum

Development Section => Your Developing Problems => Topic started by: NightLitch on 03 February, 2004, 00:17:12

Title: Reverse the Sort table HELP!
Post by: NightLitch on 03 February, 2004, 00:17:12
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.
Title:
Post by: [NL]Pur on 03 February, 2004, 00:18:52
maby a wild idea but i think the sort function is the one you need too reverse
Title:
Post by: NightLitch on 03 February, 2004, 00:27:35
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
Title:
Post by: c h i l l a on 03 February, 2004, 01:04:21
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
Title:
Post by: plop on 03 February, 2004, 03:22:54
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
Title:
Post by: c h i l l a on 03 February, 2004, 10:27:20
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
Title:
Post by: tezlo on 03 February, 2004, 12:03:09
for i = getn(tmp), 1, -1 do ..
Title:
Post by: c h i l l a on 03 February, 2004, 12:15:49
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
Title:
Post by: tezlo on 03 February, 2004, 12:51:43
you shouldnt change i inside the block.. why complicate it anyway?
Title:
Post by: c h i l l a on 03 February, 2004, 13:05:57
So is there another way? I guess not,
well if I should have problems then i'll just create another variable.
Title:
Post by: tezlo on 03 February, 2004, 13:18:14
lua has its own way.. what i just posted
for i = getn(tmp), 1, -1 do ..
Title:
Post by: c h i l l a on 03 February, 2004, 13:47:45
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

???
Title:
Post by: NightLitch on 03 February, 2004, 15:40:59
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
Title:
Post by: plop on 03 February, 2004, 15:52:24
QuoteOriginally posted by tezlo
for i = getn(tmp), 1, -1 do ..
whoeps your right, forgot the ,-1.

plop
Title:
Post by: NightLitch on 03 February, 2004, 17:24:46
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.
Title:
Post by: NightLitch on 03 February, 2004, 18:36:31
There's no need helping me more here solved it.
Title:
Post by: VidFamne on 03 February, 2004, 22:34:53
Please post the solution, so everybody in here can take benefits from it.
Title:
Post by: NightLitch on 03 February, 2004, 22:37:49
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
Title:
Post by: plop on 04 February, 2004, 03:41:18
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
Title:
Post by: c h i l l a on 04 February, 2004, 18:53:30
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?