PtokaX forum

Development Section => Your Developing Problems => Topic started by: NightLitch on 14 December, 2003, 01:48:22

Title: Need Some Help Here Guys...
Post by: NightLitch on 14 December, 2003, 01:48:22
How do I make this reboot....

function Main()
local f = openfile(sIniFile, "w")
if  f == nil then
doReadIni()
doSaveInifile()
frmHub:RegBot(BotName)
else
frmHub:RegBot(BotName)
end
end

I want it if File is emty to doReadIni() and doSaveIni(), if not emty nothing is done... how do I do that...

The ini contain every data such as BotName etc.

plz help me...

/NL
Title:
Post by: pHaTTy on 14 December, 2003, 01:58:04
well first off, you have it as write open

you first wanna open as read so, i guess sumit like this bro,


function Main()
local f = readfrom(IniFile)
if  f == " " then
doReadIni()
doSaveInifile()
frmHub:RegBot(BotName)
else
frmHub:RegBot(BotName)
end
end


try that bro...
Title:
Post by: NightLitch on 14 December, 2003, 02:02:17
it doesn't work Phatty or maybe something is worng.. posted the functions thats trigger...

sIniFile = "settings.ini"
MSR = {}
MOD = {}
OPR = {}
VIP = {}
REG1 = {}
REG2 = {}
REG3 = {}
USR = {}

function Main()
local f = readfrom(sIniFile)
if  f == " " then
doReadIni()
doSaveInifile()
frmHub:RegBot(BotName)
else
frmHub:RegBot(BotName)
end
end

function doReadIni()
BotName = BotName or "-LinK-"
MstrLvl = MstrLvl or 5
MSR.MinShare = MSR.MinShare or 10
MSR.MaxShare = MSR.Maxhare or 500
MSR.MinSlots = MSR.MinSlots or 3
MSR.MaxSlots = MSR.MaxSlots or 15
ModLvl = ModLvl or 6
MOD.MinShare = MOD.MinShare or 10
MOD.MaxShare = MOD.Maxhare or 500
MOD.MinSlots = MOD.MinSlots or 3
MOD.MaxSlots = MOD.MaxSlots or 15
OprLvl = OprLvl or 1
OPR.MinShare = OPR.MinShare or 10
OPR.MaxShare = OPR.Maxhare or 500
OPR.MinSlots = OPR.MinSlots or 3
OPR.MaxSlots = OPR.MaxSlots or 15
VipLvl = VipLvl or 2
VIP.MinShare = VIP.MinShare or 10
VIP.MaxShare = VIP.Maxhare or 500
VIP.MinSlots = VIP.MinSlots or 3
VIP.MaxSlots = VIP.MaxSlots or 15
Reg1Lvl = Reg1Lvl or 3
REG1.MinShare = REG1.MinShare or 10
REG1.MaxShare = REG1.Maxhare or 500
REG1.MinSlots = REG1.MinSlots or 3
REG1.MaxSlots = REG1.MaxSlots or 15
Reg2Lvl = Reg2Lvl or 4
REG2.MinShare = REG2.MinShare or 10
REG2.MaxShare = REG2.Maxhare or 500
REG2.MinSlots = REG2.MinSlots or 3
REG2.MaxSlots = REG2.MaxSlots or 15
Reg3Lvl = Reg3Lvl or 5
REG3.MinShare = REG3.MinShare or 10
REG3.MaxShare = REG3.Maxhare or 500
REG3.MinSlots = REG3.MinSlots or 3
REG3.MaxSlots = REG3.MaxSlots or 15
UsrLvl = UsrLvl or -1
USR.MinShare = USR.MinShare or 10
USR.MaxShare = USR.Maxhare or 500
USR.MinSlots = USR.MinSlots or 3
USR.MaxSlots = USR.MaxSlots or 15
end
-------------------------------------------------------------------------------------------------------------
function doSaveInifile()
local sIni = ""
sIni = sIni .. "-- Settings --"
sIni = sIni .. "\n"
sIni = sIni .. "\nBotName = \""..BotName .."\""
sIni = sIni .. "\n"
sIni = sIni .. "\n -- Master --"
sIni = sIni .. "\nMstrLvl = "..MstrLvl
sIni = sIni .. "\nMSR = {"
sIni = sIni .. "\nMinShare = "..MSR.MinShare..","
sIni = sIni .. "\nMaxShare = "..MSR.MaxShare..","
sIni = sIni .. "\nMinSlots = "..MSR.MinSlots..","
sIni = sIni .. "\nMaxSlots = "..MSR.MaxSlots..","
sIni = sIni .. "\n}"
sIni = sIni .. "\n"
sIni = sIni .. "\n -- Moderator --"
sIni = sIni .. "\nModLvl = "..ModLvl
sIni = sIni .. "\nMOD = {"
sIni = sIni .. "\nMinShare = "..MOD.MinShare..","
sIni = sIni .. "\nMaxShare = "..MOD.MaxShare..","
sIni = sIni .. "\nMinSlots = "..MOD.MinSlots..","
sIni = sIni .. "\nMaxSlots = "..MOD.MaxSlots..","
sIni = sIni .. "\n}"
sIni = sIni .. "\n"
sIni = sIni .. "\n -- Operator --"
sIni = sIni .. "\nOprLvl = "..OprLvl
sIni = sIni .. "\nOPR = {"
sIni = sIni .. "\nMinShare = "..OPR.MinShare..","
sIni = sIni .. "\nMaxShare = "..OPR.MaxShare..","
sIni = sIni .. "\nMinSlots = "..OPR.MinSlots..","
sIni = sIni .. "\nMaxSlots = "..OPR.MaxSlots..","
sIni = sIni .. "\n}"
sIni = sIni .. "\n"
sIni = sIni .. "\n -- Vip User --"
sIni = sIni .. "\nVipLvl = "..VipLvl
sIni = sIni .. "\nVIP = {"
sIni = sIni .. "\nMinShare = "..VIP.MinShare..","
sIni = sIni .. "\nMaxShare = "..VIP.MaxShare..","
sIni = sIni .. "\nMinSlots = "..VIP.MinSlots..","
sIni = sIni .. "\nMaxSlots = "..VIP.MaxSlots..","
sIni = sIni .. "\n}"
sIni = sIni .. "\n"
sIni = sIni .. "\n -- Reg User 1 --"
sIni = sIni .. "\nReg1Lvl = "..Reg1Lvl
sIni = sIni .. "\nREG1 = {"
sIni = sIni .. "\nMinShare = "..REG1.MinShare..","
sIni = sIni .. "\nMaxShare = "..REG1.MaxShare..","
sIni = sIni .. "\nMinSlots = "..REG1.MinSlots..","
sIni = sIni .. "\nMaxSlots = "..REG1.MaxSlots..","
sIni = sIni .. "\n}"
sIni = sIni .. "\n"
sIni = sIni .. "\n -- Reg User 1 --"
sIni = sIni .. "\nReg1Lvl = "..Reg1Lvl
sIni = sIni .. "\nREG1 = {"
sIni = sIni .. "\nMinShare = "..REG1.MinShare..","
sIni = sIni .. "\nMaxShare = "..REG1.MaxShare..","
sIni = sIni .. "\nMinSlots = "..REG1.MinSlots..","
sIni = sIni .. "\nMaxSlots = "..REG1.MaxSlots..","
sIni = sIni .. "\n}"
sIni = sIni .. "\n"
sIni = sIni .. "\n -- Reg User 3 --"
sIni = sIni .. "\nReg3Lvl = "..Reg3Lvl
sIni = sIni .. "\nREG3 = {"
sIni = sIni .. "\nMinShare = "..REG3.MinShare..","
sIni = sIni .. "\nMaxShare = "..REG3.MaxShare..","
sIni = sIni .. "\nMinSlots = "..REG3.MinSlots..","
sIni = sIni .. "\nMaxSlots = "..REG3.MaxSlots..","
sIni = sIni .. "\n}"
sIni = sIni .. "\n"
sIni = sIni .. "\n -- Regular User --"
sIni = sIni .. "\nUsrLvl = "..UsrLvl
sIni = sIni .. "\nUSR = {"
sIni = sIni .. "\nMinShare = "..USR.MinShare..","
sIni = sIni .. "\nMaxShare = "..USR.MaxShare..","
sIni = sIni .. "\nMinSlots = "..USR.MinSlots..","
sIni = sIni .. "\nMaxSlots = "..USR.MaxSlots..","
sIni = sIni .. "\n}"
sIni = sIni .. "\n"
writeto(sIniFile)
write(sIni)
writeto()
end


help me bro  :-)

/NL
Title:
Post by: pHaTTy on 14 December, 2003, 02:30:59
Hmm the way this is written its pretty difficult for my style but i try help :))

try, hmmmm


function Main()
dofile(sIniFile)
if not strfind == "USR.MaxSlots" then
doReadIni()
doSaveInifile()
frmHub:RegBot(BotName)
else
frmHub:RegBot(BotName)
end
end

Title:
Post by: NightLitch on 14 December, 2003, 03:18:27
THX alot Phatty m8...

It is working great now...

/NL
Title:
Post by: NightLitch on 14 December, 2003, 03:19:33
but I changed it to this becouse yours didn't work but the
way you did it, why didn't I think of that... :-)

function Main()
dofile(sIniFile)
if not strfind == MSR.Lvl then
doReadIni()
doSaveInifile()
frmHub:RegBot(BotName)
else
LF(sIniFile)
frmHub:RegBot(BotName)
end
end

/NL
Title:
Post by: NightLitch on 14 December, 2003, 03:20:19
by the way, if the DoFile is trigger, do I need LF(ReadFile) then ???
Title:
Post by: pHaTTy on 14 December, 2003, 03:23:54
i dont quite understadn what you mean.......can you explain...?
Title:
Post by: NightLitch on 14 December, 2003, 03:28:39
Does the - dofile  - have the same function as if I
use a own function ex:




function LoadFile(file)
    assert(readfrom(file),"No File Found")
    dostring(read("*all"))
    readfrom()
end


is this the same ???
Title:
Post by: pHaTTy on 14 December, 2003, 03:35:45
hmm i guess so, but that wud be slower yep...
Title:
Post by: NightLitch on 14 December, 2003, 03:37:22
the function or dofile ???

I use dofile now saw that it worked so using that istead of
that function...

/NL
Title:
Post by: pHaTTy on 14 December, 2003, 03:42:31
function will be slower yep