PtokaX forum

Archive => Archived 5.0 boards => Help with scripts => Topic started by: Snooze on 20 May, 2005, 21:46:26

Title: [Advice]faster way to do this ..
Post by: Snooze on 20 May, 2005, 21:46:26
The code should explain itself.. just looking for a faster/better way to do it.

function doArrayCheck(user,data)
local tday = {
["0"] = "Sunday",
["1"] = "Monday",
["2"] = "Tuesday",
["3"] = "Wednesday",
["4"] = "Thursday",
["5"] = "Friday",
["6"] = "Saturday",
}
if (user.iShareSize and user.iHubs and user.iSlots  nil and user.sClientVersion  nil) then
for i=1,table.getn(tArrayOrder) do
if tArray[tArrayOrder[i]]["Status"] == "ON" then
if (user.iShareSize/1024/1024/1024) >= tonumber(tArray[tArrayOrder[i]]["MinShare"]) and tonumber(user.sClientVersion) >= tonumber(tArray[tArrayOrder[i]]["MinClient"]) and user.iHubs <= tonumber(tArray[tArrayOrder[i]]["MaxHubs"]) and user.iSlots >= tonumber(tArray[tArrayOrder[i]]["MinSlots"]) and user.iSlots <= tonumber(tArray[tArrayOrder[i]]["MaxSlots"]) then
user:SendData("*** The Insanity Array is directing you to a hub fitting your settings..")
if not tArrayCheck[user.sName] then
user:Redirect(tArray[tArrayOrder[i]]["Addy"])
user:Disconnect()
tArrayStats[tArrayOrder[i]][tday[os.date("%w")]] = tArrayStats[tArrayOrder[i]][tday[os.date("%w")]] + 1
doArrayMe(user, "[ "..user.sName.." ] --> [ "..tArrayOrder[i].." ]")
tArrayCheck[user.sName] = 1
return 1
elseif (tonumber(i + tArrayCheck[user.sName]) <= tonumber(tArrayOrder["n"])) then
user:Redirect(tArray[tArrayOrder[i + tArrayCheck[user.sName]]]["Addy"])
user:Disconnect()
tArrayStats[tArrayOrder[i + tArrayCheck[user.sName]]][tday[os.date("%w")]] = tArrayStats[tArrayOrder[i + tArrayCheck[user.sName]]][tday[os.date("%w")]] + 1
doArrayMe(user, "[ "..user.sName.." ] --> [ "..tArrayOrder[i + tArrayCheck[user.sName]].." ]("..tArrayCheck[user.sName]..")")
tArrayCheck[user.sName] = tArrayCheck[user.sName] + 1
return 1
else
user:Redirect(frmHub:GetRedirectAddress())
user:Disconnect()
doArrayMe(user, "[ "..user.sName.." ] --> [ "..frmHub:GetRedirectAddress().." ]*")
tArrayCheck[user.sName] = nil
user:TimeBan(5)
return 1
end
end
end
end
user:Redirect(frmHub:GetRedirectAddress())
user:Disconnect()
doArrayMe(user, "[ "..user.sName.." ] --> [ "..frmHub:GetRedirectAddress().." ]*")
return 1
end
end

Any advice would be great :)


Snooze
Title:
Post by: [NL]Pur on 21 May, 2005, 00:17:11
Putting alot of code on 1 line won't make it faster.

my first advice whould be, try to put less code on a line it makes it easier to read.
Title:
Post by: Snooze on 21 May, 2005, 04:54:13
Edited to the advise of Hawk - thanks ...

still waiting for plop.. seem to remeber you adding acomment ?

Feel free to break the code at any point where it feel natural.
Title:
Post by: Dessamator on 21 May, 2005, 11:33:45
i suggest using a function to handle the repitition in the code !
Title:
Post by: kepp on 21 May, 2005, 12:10:47
If you are sure of that table contents are numbers conversion tonumber is not needed.
or if you are sure that variables are numbers then conversion
is slow and unecesary
Title:
Post by: Optimus on 21 May, 2005, 12:52:22
QuoteIf you are sure of that table contents are numbers conversion tonumber is not needed.
or if you are sure that variables are numbers then conversion
is slow and unecesary
Yep that means summ like this.

local tday = {
[0] = "Sunday",
[1] = "Monday",
[2] = "Tuesday",
[3] = "Wednesday",
[4] = "Thursday",
[5] = "Friday",
[6] = "Saturday",
}


- Optimus
Title:
Post by: Dessamator on 21 May, 2005, 13:07:21
or just use the os.date function ,  ;)