PtokaX forum

Development Section => Your Developing Problems => Topic started by: EXNET OWNER on 01 September, 2004, 14:25:15

Title: How To
Post by: EXNET OWNER on 01 September, 2004, 14:25:15
I have a bot with the following variables and i am having no luck at creatniga working .ini file so that the variables are read from the file rather than the script. Could someone please make create a .ini file for a bot witht the following variables, thankyou...

BotName = "-???OwL???-"
Description = ""
Connection = "DSL"
Version = "0.500"
Mode = "A"
HubsOp = "1"
HubsReg = "0"
HubsGuest = "0"
Slots = "3"
Tag = "<++ V:"..Version..",M:"..Mode..",H:"..HubsGuest.."/"..HubsReg.."/"..HubsOp..",S:"..Slots..">"
Email = "None"
Share = 6958739042 -- In Bytes not KB, MB or GB

I hope somoen could help me as I am finding this really hard :)
Title:
Post by: Psycho_Chihuahua on 01 September, 2004, 14:28:58
can u post the script to?


Otherwise check get Black_Pearl to read settings from cfg file (http://board.univ-angers.fr/action.php?action=getlastboard&threadid=2644&boardid=13) for a similar example
Title:
Post by: nErBoS on 01 September, 2004, 21:47:38
Hi,

Simple as this...

fSetting = "setting.ini" -- Path of the file

function Main()
assert(dofile(fSetting),"File Setting.ini was not Found.")
end

Best regards, nErBoS
Title:
Post by: BottledHate on 02 September, 2004, 03:49:23
this is one way to load settings from an ini style file.


--//LUA4 / PTOKAX
readfrom("yourfile.bleh")
while 1 do
   local line = read()
   if (line == nil) then
      break
   else
      if strsub(line,1,9) =="Status =" then
         setting1=strsub(line,9,srlen(line))
      elseif strsub(line..........................
         setting2=strsub(line...............
      end
end
readfrom()

this show u 'HOW TO' do it. it does not do it for you.  

saveing in an ini style file.
--BotName = "-???OwL???-"
--Description = ""
--Connection = "DSL"
--Version = "0.500"

function inistyledata()
local tmp = ""
local tmp = "[Settings]\r\n"..
                     "BotName = "..BotName.."\r\n"..
                     "Description = "..Description.."\r\n"..
                     "Connectoin = "..Connectoin.."\r\n"..
                     "Versoin = "..Versoin.."\r\n"
return tmp
end

local f,e = openfile( "yourfilename.bleh", "w+" )
   if f then
     write(f, inistyledata() )
     closefile(f)
   end

Is the ini file for the user of the script to change??? or just for saving data... if it is just for saving data i recommend putting all you data in 1 table, and user serialization to save and dofile() to load. much faster and more reliable than the way you are doing it now.

i'm working on a lil 'how to' for saving and loading strings and tables, and creating files and paths..... keep an eye out for it.


:D

-BH