PtokaX forum

Development Section => Your Developing Problems => Topic started by: bastya_elvtars on 05 March, 2005, 01:52:26

Title: os.clock()
Post by: bastya_elvtars on 05 March, 2005, 01:52:26
if cmd then
local x=os.clock()
if parsecmds(user,data,string.lower(cmd),"MAIN") then
if LagTest==1 then
[color=#993399]user:SendData(parseenv(user,env,Bot).."Executing this command took "..os.clock() - x.." seconds.")[/color]
end
return 1
else
user:SendPM(Bot,"It would be so nice to talk to you, but I have many things to do. So either enter a valid command or stop bugging me! ;)")
end
end

Any ideas why this gives the following error?

QuoteSyntax O:\ptokax1604\scripts\lawmaker.lua:4262: attempt to concatenate a nil value
Title:
Post by: Pothead on 05 March, 2005, 02:15:03
Which line is 4262 ? :)
Title:
Post by: bastya_elvtars on 05 March, 2005, 02:46:03
QuoteOriginally posted by Pothead
Which line is 4262 ? :)

The one containing concatenation. :D

OK, I made it purle.
Title:
Post by: Psycho_Chihuahua on 05 March, 2005, 04:19:15
probably not what ur lookin for...

current = os.date("%d:%m:%y - %H:%M")
iMin = 1000*60
tTime = {
--["timestring"] = "show this string"
["06:00"] = "Guten Morgen Hub - Ein neuer Tag ist angebrochen!!",
["09:30"] = "Morgens halb zehn in Deutschland - KNOPPERS Das Fr?hst?ckchen!! Mahlzeit *fg*",
["12:00"] = "Guten hunger, all denen die nun was essen!!",
["22:00"] = "Gut nacht, all denen die schon oder gleich ins Bett gehen!"
}
function Main()
current = os.date("%d:%m:%y - %H:%M")
if tTime[current] then
SendToAll( ("---" ..current .."---"), tTime[current] )
end
frmHub:RegBot("---" ..current .."---")
SetTimer(iMin)
StartTimer()
end
function OnTimer()
frmHub:UnregBot("---" ..current .."---")
current = os.date("%d:%m:%y - %H:%M")
if tTime[current] then
SendToAll( ("---" ..current .."---"), tTime[current] )
end
frmHub:RegBot("---" ..current .."---")
end
function OnExit()
frmHub:UnregBot("---" ..current .."---")
end

but maybe something inside could help u
Title:
Post by: Herodes on 05 March, 2005, 09:43:43
user:SendData(parseenv(user,env,Bot).."Executing this command took "..os.clock() - x.." seconds.")Make sure that parseenv(user,env,Bot) is actually returning smth with the parameters ... and also it'll be poss cleaner to parenthesize (os.clock()-x) while concating it ...
Hope its solved by the time you r reading this .. ;)
Title:
Post by: NightLitch on 05 March, 2005, 10:24:41
when handling 2 values inside a string do it like this:

user:SendData(parseenv(user,env,Bot).."Executing this command took "..(os.clock() - x).." seconds.")

My coin to this... cheers
Title:
Post by: bastya_elvtars on 05 March, 2005, 12:35:34
The fun is that it works here:

function Main()
local x=os.clock()
if not string.find(frmHub:GetHubDescr(), "LawMaker") then
local tempdescstore = frmHub:GetHubDescr()
local NewDescription = tempdescstore.." - powered by "..botver
frmHub:SetHubDescr(NewDescription)
end
ipranges=loadipranges()
local f=io.open("lawmaker/getlogs.bat","w+")
f:write("dir \""..ptokaxpath.."/scripts/lawmaker/logs\" %1 /-p /o:gn > \""..ptokaxpath.."/scripts/lawmaker/lists/logs.lst\"")
f:close()
-- Cleaning()
loadwatchkicks()
immunelist=maketable("lawmaker/lists/immune.lst")
bannedranges=maketable("lawmaker/lists/banned_ranges.lst")
CleanDay = os.date("%Y. %m. %d.")
if loadfile("lawmaker/inifiles/offline.ini") then
require("lawmaker/inifiles/offline.ini")
end
if loadfile("lawmaker/inifiles/announce.ini") then
require("lawmaker/inifiles/announce.ini")
end
if loadfile("lawmaker/inifiles/leave.ini") then
require("lawmaker/inifiles/leave.ini")
end
GetOpVipChat()
LoadFile(opchat,"lawmaker/inifiles/opchat.ini")
LoadFile(vipchat,"lawmaker/inifiles/vipchat.ini")
-- botversion(nil,"MAIN",nil)
-- frmHub:EnableFullData(1)
frmHub:RegBot(Bot)
frmHub:RegBot(opchatbot)
--frmHub:UnRegBot(vipchatbot)
if enablevipchat==1 then frmHub:RegBot(vipchatbot) end
fakeshares=maketable("lawmaker/inifiles/fakesharesize.ini")
NoClean=maketable("lawmaker/lists/noclean.lst")
NoMotd=maketable("lawmaker/lists/nomotd.lst")
LoadWarn()
SetTimer(1000)
StartTimer()
ReloadRel()
loadaway()
kicks=loadkicks()
NoMotd=maketable("lawmaker/lists/nomotd.lst")
userinfo=nil
Clear()
userinfo={}
LoadUserInfo()
SaveUserinfo()
SendToOps(Bot,"Booting... done in "..os.clock()-x.." seconds.")
end

@Herodes: parseenv is about 100 times called in my script. IMHO it's the command parsing that flushes it. Gonna try with GLOBAL variable. :S
Title:
Post by: bastya_elvtars on 07 March, 2005, 04:33:22
Gonna try with GLOBAL variable.
Does not work either. Need workaround,
Title:
Post by: bastya_elvtars on 07 March, 2005, 06:03:02
*was an idiot*

Thx to RabidWombat for directing my attention to parseenv, that was erroneous - altho I still do not 100% understand why.