Author Topic: Need some help here...  (Read 2721 times)

0 Members and 1 Guest are viewing this topic.

Offline NightLitch

  • Emperor
  • **
  • Posts: 1 455
  • Karma: +16/-0
Need some help here...
« on: 27 October, 2003, 18:23:12 »
I want when I write this INI file that the Table looks like this:

TABLE = {"[NAME1]","[NAME2]"}
how do I change this so it writes like above

and Not:

TABLE = {"[NAME1]"}
TABLE = {"[NAME2]"}


with this:

for key,nick in BadISP do
sIni = sIni .. "\r\nBadISP = {\""..nick.."\"}"
end


pls help me / NightLitch
//NL

PtokaX forum

Need some help here...
« on: 27 October, 2003, 18:23:12 »

Offline c h i l l a

  • Lord
  • ***
  • Posts: 347
  • Karma: +1/-0
(No subject)
« Reply #1 on: 27 October, 2003, 18:34:52 »
write(handle, tablename.." = {\n" )
   for key, value in table do
      write(handle, "\t"..format("[%q]",key).." = "..value..",\n")
   end
write(handle, "}");

if this is about you nick rule its gonna be added to the Logger ;). And it works already it only need some rewriting.
« Last Edit: 27 October, 2003, 18:36:45 by c h i l l a »

Offline NightLitch

  • Emperor
  • **
  • Posts: 1 455
  • Karma: +16/-0
(No subject)
« Reply #2 on: 27 October, 2003, 18:38:22 »
Ok Chilla am way off now...

How would this look like I have just pasted and ...

plz correct...

Code: [Select]
function doSaveInifile(curUser)
local sIni = ""
sIni = sIni .. "\r\n--[ BotName ]--"
sIni = sIni .. "\r\nBot = \""..Bot.."\""
sIni = sIni .. "\r\n--[ USER LOG NAME/IP ]--"
sIni = sIni .. "\r\nUSERLOG = \""..USERLOG.."\" --// enable/disable"
sIni = sIni .. "\r\n--[ Bad Network ISP's ]--"
sIni = sIni .. "\r\nISPCHECK = \""..ISPCHECK.."\" --// enable/disable"
for key,nick in BadISP do
sIni = sIni .. "\r\nBadISP = {\""..nick.."\"}"
end
sIni = sIni .. "\r\n"

-- open and write to file
writeto(sIniFile)
write(sIni)
writeto()
curUser:SendData("$To: "..curUser.sName.." From: "..Bot.." $***Settings saved to file")
dofile("IP-Boter.ini")
end

/NightLitch
« Last Edit: 27 October, 2003, 18:39:26 by NightLitch »
//NL

Offline NightLitch

  • Emperor
  • **
  • Posts: 1 455
  • Karma: +16/-0
(No subject)
« Reply #3 on: 27 October, 2003, 18:40:42 »
And No this is for my IP-BOTER...

Just doing this to learn some more...

But have got stuck...

so need your or someone else's help...
//NL

Offline c h i l l a

  • Lord
  • ***
  • Posts: 347
  • Karma: +1/-0
(No subject)
« Reply #4 on: 27 October, 2003, 18:46:44 »
if you only want to save one tablke containg only a key and a value where value is not a table again this simple thing should do.

Code: [Select]

table = YOURTABLE
tablename = "TABLENAME"
YOURFILE = "PATHANDFILE"

local handle = openfile(YOURFILE, "w")
write(handle, tablename.." = {\n" )
for key, value in table do
write(handle, "\t"..format("[%q]",key).." = "..value..",\n")
end
write(handle, "}");

for advanced serialisation use this from RabidWombat..
damn where is he miss him a lot, he was the best...

Code: [Select]
function WriteFile(table,tablename,file)
local handle = openfile(file,"w")
Serialize(table,tablename,handle)
  closefile(handle)
end
----------------------------------------------------------------------------------------------------------------------------------------------
function Serialize(tTable,sTableName,hFile,sTab)
sTab = sTab or "";
write(hFile,sTab..sTableName.." = {\n");
for key,value in tTable do
local sKey = (type(key) == "string") and format("[%q]",key) or format("[%d]",key);
if(type(value) == "table") then
Serialize(value,sKey,hFile,sTab.."\t");
else
local sValue = (type(value) == "string") and format("%q",value) or tostring(value);
write(hFile,sTab.."\t"..sKey.." = "..sValue);
end
write(hFile,",\n");
end
write(hFile,sTab.."}");
end

Offline tezlo

  • Triple Ace
  • **
  • Posts: 225
  • Karma: +1/-0
(No subject)
« Reply #5 on: 27 October, 2003, 18:47:36 »
whats the point in letting others write your script ?
youll never know what goes on in it and youll never learn

Offline NightLitch

  • Emperor
  • **
  • Posts: 1 455
  • Karma: +16/-0
(No subject)
« Reply #6 on: 27 October, 2003, 18:52:30 »
Wanna now the truth so I have almost fixed it myself...
//NL

Offline NightLitch

  • Emperor
  • **
  • Posts: 1 455
  • Karma: +16/-0
(No subject)
« Reply #7 on: 27 October, 2003, 18:55:03 »
Have one problem doo...

Code: [Select]
local l = {}
for k,v in BadISP do
tinsert(l,k)
end
sort(l)

local s = "BadISP = {"
for i=1, l.n do
s = s .. "\[\"" .. l[i] .. "\"\] = \"" .. tostring(BadISP[l[i]]) .. "\""
end
local s = s.."}"
sIni = sIni .. (s)

I only want it to write the name not number...
//NL

Offline NightLitch

  • Emperor
  • **
  • Posts: 1 455
  • Karma: +16/-0
(No subject)
« Reply #8 on: 27 October, 2003, 19:04:14 »
No need to help me... I have solved it myself again...

But I thank you all for the help...

It's funny how the head can stand still a minute or two :-p and then I just get it working...

ThX Guys / NightLitch
//NL

PtokaX forum

(No subject)
« Reply #8 on: 27 October, 2003, 19:04:14 »