How to sort this Table??
 

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

How to sort this Table??

Started by Optimus, 11 December, 2003, 15:26:50

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Optimus

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

c h i l l a

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

--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

Optimus

there seems to be something wrong with this Line:

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

c h i l l a

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

Guibs

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

Optimus

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

Guibs

-- 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

Optimus

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

Guibs

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

Optimus

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,
},
}

Guibs

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

SMF spam blocked by CleanTalk