Author Topic: How to sort this Table??  (Read 3407 times)

0 Members and 1 Guest are viewing this topic.

Offline Optimus

  • Emperor
  • **
  • Posts: 1 474
  • Karma: +13/-1
How to sort this Table??
« on: 11 December, 2003, 15:26:50 »
Hi guy's i'm trying to sort this Table, but without any succes.

if (cmd == "!show") then
         n=1
         local disp = ""
         disp = disp.."\t\tNr:\tTime:\tNick:\r\n"
         for i,v in UserHubTime do
            local T = UserHubTime["Total"]
               disp = disp.."\t\t"..n..".\t"..T.." min\t"..i.."\r\n"
               n = n + 1
            end
               user:SendData(sBot, disp)
            end
         end


Thx allready L8trs

PtokaX forum

How to sort this Table??
« on: 11 December, 2003, 15:26:50 »

Offline c h i l l a

  • Lord
  • ***
  • Posts: 347
  • Karma: +1/-0
(No subject)
« Reply #1 on: 11 December, 2003, 15:36:41 »
Buy,  entering all your table entries in a non assocciative table, like this


test = {}

for i, v un UserHUbTime do
  tinsert(test,{ i,v["Total"] }
end

sort(test, function(a,b) return (a[2] > b[2]) end)

or something like that...  in one of my elder scripts i also found this...  but not usefull actually..  but it works

Code: [Select]

--max is the maximum number of shown entries

function GetUserMaxTime()
TCopy={}
for i,v in UserHubTime do
TCopy[i]=v
end
local msgfromtxt ="\r\n"
for i = 1,Max do
var1 = 0
for index, value in TCopy do
value = tonumber (value)
if value > var1 then
var1 = value
userm = index
end
end
local tmp = TCopy[userm]
local months, days, hours, minutes = floor(tmp/43200), floor(mod(tmp/1440, 30)), floor(mod(tmp/60, 24)), floor(mod(tmp/1, 60))
TCopy[userm]=0
msgfromtxt = msgfromtxt.."          "..i.." - "..userm.." :: "..months.." Months, "..days.." Days, "..hours.." Hours, "..minutes.." Min ( "..tmp.." min ).\r\n"
end
return msgfromtxt
end


Offline Optimus

  • Emperor
  • **
  • Posts: 1 474
  • Karma: +13/-1
(No subject)
« Reply #2 on: 11 December, 2003, 15:45:28 »
there seems to be something wrong with this Line:

tinsert(test,{i,v["Total"]}

Offline c h i l l a

  • Lord
  • ***
  • Posts: 347
  • Karma: +1/-0
(No subject)
« Reply #3 on: 11 December, 2003, 16:08:42 »
try

tinsert(test,{i,UserHubTime.Total})

or tinsert(test,{i,UserHubTime["Total"]})

else just try around..  or just
send me a copy of the table of how it looks like

Offline Guibs

  • Double Ace
  • *
  • Posts: 142
  • Karma: +3/-0
(No subject)
« Reply #4 on: 11 December, 2003, 16:12:16 »
Hi there,,

Optimus,.. i'm not sure to get what you wish,.... but,
maybe try:
---
for i,v in UserHubTime do
local T = UserHubTime
disp = disp.."\t\t"..n..".\t"..T.." Total min\t"..i.."\r\n"
n = n + 1
end
---
If i get your idea,,,... :)

l8tr,, ;)
-- Please,... don\'t ask help in Pm,...Forums are made for that, to help everyone & my Inbox pm will be safe,... Thks,,  :))  --
CB forum     /     CB Home page

Offline Optimus

  • Emperor
  • **
  • Posts: 1 474
  • Karma: +13/-1
(No subject)
« Reply #5 on: 11 December, 2003, 16:12:35 »
kk Chilla i will send you a copy in PM.

And thx Guibs for having a look also... Structure is just abit more complex :D

Offline Guibs

  • Double Ace
  • *
  • Posts: 142
  • Karma: +3/-0
(No subject)
« Reply #6 on: 11 December, 2003, 16:31:46 »
lol,,

ok,... :o)
-- Please,... don\'t ask help in Pm,...Forums are made for that, to help everyone & my Inbox pm will be safe,... Thks,,  :))  --
CB forum     /     CB Home page

Offline Optimus

  • Emperor
  • **
  • Posts: 1 474
  • Karma: +13/-1
(No subject)
« Reply #7 on: 11 December, 2003, 16:34:57 »
Ok solved now by Chilla... Big Thanks

Code:

function GetUserMaxTime()
   TCopy={}
   for i,v in UserHubTime do
      tinsert(TCopy,{i,v.Total})
   end
   sort(TCopy,function(a,b) return (a[2] > b[2]) end)
   local msgfromtxt ="\r\n"
   for i = 1,Max do
      if TCopy then
         msgfromtxt = msgfromtxt..""..i.." - "..TCopy[1].." :: "..TCopy[2].."\r\n"
      end
   end
   return msgfromtxt
end

Offline Guibs

  • Double Ace
  • *
  • Posts: 142
  • Karma: +3/-0
(No subject)
« Reply #8 on: 11 December, 2003, 16:41:23 »
looks very nice, yep,...
Thks to both of you to have post this syntax,... :)

l8tr,, ;)
-- Please,... don\'t ask help in Pm,...Forums are made for that, to help everyone & my Inbox pm will be safe,... Thks,,  :))  --
CB forum     /     CB Home page

Offline Optimus

  • Emperor
  • **
  • Posts: 1 474
  • Karma: +13/-1
(No subject)
« Reply #9 on: 11 December, 2003, 16:48:33 »
Hihi, no prob Guibs m8

Btw, this was the reason for the Sorting Structure...
Having a abnormal Table *lol*

{{
["[SU]Guibs"]={2},
["[SU]Me"]={3},
},
{
["Session"]=56,
["Total"]=101,
},
{
["Session"]=34,
["Total"]=86,
},
}

Offline Guibs

  • Double Ace
  • *
  • Posts: 142
  • Karma: +3/-0
(No subject)
« Reply #10 on: 11 December, 2003, 18:43:11 »
h? h? h?
yup, i get your '["Total"]' problem,, now,.. ;)
-- Please,... don\'t ask help in Pm,...Forums are made for that, to help everyone & my Inbox pm will be safe,... Thks,,  :))  --
CB forum     /     CB Home page

PtokaX forum

(No subject)
« Reply #10 on: 11 December, 2003, 18:43:11 »