Problem with WriteData() function
 

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

Problem with WriteData() function

Started by icculus, 21 December, 2003, 10:15:13

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

icculus

I have a problem with this function:

function WriteData()
   datafile = openfile("MyBot/settings.dat","w+")
   for i=1,DataTotal,1 do
      write(datafile, rawget(DataList,i).."\n")
   end
   closefile(datafile)
end

the problem is that is when it is called it duplicates all lines into new lines

ie:
(this is what it looks like before i call the function)
-----DO NOT EDIT THIS FILE---------
0.263
7
2
15
10
on
on
nowhere.no-ip.com
nowhere.no-ip.com
nowhere.no-ip.com
nowhere.no-ip.com
nowhere.no-ip.com

(this is what it looks like after function is called)
-----DO NOT EDIT THIS FILE---------
0.263
7
2
15
10
on
on
nowhere.no-ip.com
nowhere.no-ip.com
nowhere.no-ip.com
nowhere.no-ip.com
nowhere.no-ip.com
-----DO NOT EDIT THIS FILE---------
0.24
7
2
15
10
on
on
nowhere.no-ip.com
nowhere.no-ip.com
nowhere.no-ip.com
nowhere.no-ip.com
nowhere.no-ip.com

Please if some could help me out with this that would be great. :))

plop

give this a try.
function WriteData()
   file = "MyBot/settings.dat"
   remove(file)
   datafile = openfile(file,"w+")
   for i=1,DataTotal,1 do
      write(datafile, rawget(DataList,i).."\n")
   end
   closefile(datafile)
end
plop
http://www.plop.nl lua scripts/howto\'s.
http://www.thegoldenangel.net
http://www.vikingshub.com
http://www.lua.org

>>----> he who fights hatred with hatred, drives the spreading of hatred <----<<

icculus

thanx plop that worked
you the man
 :]

icculus

That helps with some of the commands... but not all... it duplicates even more ... here is some more info:

function ReadData()
   readfrom("Mybot/settings.dat")
   while 1 do
      local line = read()
      if line == nil then
         break
      else
         DataTotal = DataTotal + 1
         rawset(DataList,DataTotal,line)
      end
   end
   readfrom()
      dcversion = tonumber(rawget(DataList,2))
      minshare = tonumber(rawget(DataList,3))
      slotsmin = tonumber(rawget(DataList,4))
      slotsmax = tonumber(rawget(DataList,5))
      maxhubs = tonumber(rawget(DataList,6))
      Redirect = rawget(DataList,7)
      AllowNonDCPP = rawget(DataList,8)
      RedirSlots = rawget(DataList,9)
      RedirShare = rawget(DataList,10)
      RedirMaxHubs = rawget(DataList,11)
      Redirdcv = rawget(DataList,12)
      Redirnondcpp = rawget(DataList,13)
end

function WriteData()
   datafile = openfile("MyBot/settings.dat","w+")
   for i=1,DataTotal,1 do
      write(datafile, rawget(DataList,i).."\n")
   end
   closefile(datafile)
end

--------sample of a function call:--------------
function dosetredirhubs(user)
   rawset(DataList,11,redirhubs)
   WriteData()
   ReadData()
   SendPmToNick(user.sName, Bot, "I have set the redirection of maximum hubs to: "..redirhubs)
end

function dosetredirdcppv(user)
   rawset(DataList,12,redirdcppv)
   WriteData()
   ReadData()
   SendPmToNick(user.sName, Bot, "I have set the redirection of minimum DC++ version to: "..redirdcppv)
end

function dosetredirnondcpp(user)
   rawset(DataList,13,redirnondcpp)
   WriteData()
   ReadData()
   SendPmToNick(user.sName, Bot, "I have set the redirection address for non-DC++ clients to: "..redirnondcpp)
end

-----------------------------------------------------------
I think the ReadData() and WriteData() are by Snowman the maker of mean machine ....hey snow how bout some help?

turkiye


plop

would be maby handyer 2 change layout of the file.
redirhubs:nowhere.no-ip.com
slots:4
then convert this 2 an associative array on load, this way you can just save the table if something changes.
makes it a lot easyer and no doubles posible as you can everywhere just remove the old file and save the new.
also doesn't mather anymore on witch line something is stored.
settings[redirhubs]="nowhere.no-ip.com"
savetable()
1st line of savetable would remove the old file followed by the stuff 2 build a fresh new file.
also drops the need 2 load the file again after a save.

plop
http://www.plop.nl lua scripts/howto\'s.
http://www.thegoldenangel.net
http://www.vikingshub.com
http://www.lua.org

>>----> he who fights hatred with hatred, drives the spreading of hatred <----<<

icculus

i am fairly new to LUA... but I will do some reading and see if I can figure that out and pull it off..
Thanx for your time plop.. :D

plop

http://www.plop.nl lua scripts/howto\'s.
http://www.thegoldenangel.net
http://www.vikingshub.com
http://www.lua.org

>>----> he who fights hatred with hatred, drives the spreading of hatred <----<<

SMF spam blocked by CleanTalk