[Advice]faster way to do this ..
 

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

[Advice]faster way to do this ..

Started by Snooze, 20 May, 2005, 21:46:26

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Snooze

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

[NL]Pur

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.

Snooze

#2
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.

Dessamator

i suggest using a function to handle the repitition in the code !
Ignorance is Bliss.

kepp

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
Guarding    

Optimus

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

Dessamator

or just use the os.date function ,  ;)
Ignorance is Bliss.

SMF spam blocked by CleanTalk