Forum

> > CS2D > Scripts > Read from ini file
Forums overviewCS2D overview Scripts overviewLog in to reply

English Read from ini file

6 replies
To the start Previous 1 Next To the start

old Read from ini file

Marcell
Super User Off Offline

Quote
Welcome UnrealSoftware's users,

I would like to know how can i read from inifile... and use it in functions, because i tried to make an inifile which have some lines like
1
2
fog 1
fps 1
and i would like to do that
if fog = 1 then
parse these functions
else do not run these functions?

anyone else who could help?

old Re: Read from ini file

Alistaire
User Off Offline

Quote
1
2
3
4
5
6
7
--[[.ini file]]--

--Setting 1
lol = true

--Setting 2
dicks = false

1
2
3
--[[load ini]]--

dofile(yourini.ini)


If you dofile() any file, it will be parsed as Lua. Just make any file with declarations in it and dofile() it.

old Re: Read from ini file

Marcell
Super User Off Offline

Quote
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
local iniFile_Path = "sys/logs.ini"

function io.exists(name)
        if iniFile_Path~="sys/logs.ini" then return false end
        return os.rename(name, name) and true or false
end

function LoadiniFile()
        local loaded = {}
        if io.exists(iniFile_Path) then
                local file = io.open(IniFile_Path, "r")
                for line in file.readLine do
                        local key, value = line:match('([%w_]+)%s+(.*)')
                        loaded[key] = tonumber(value) or value
                end
                return loaded, file:close()
        else
                print("©255000000[Advanced Log] Something went wrong")
        end
end

LoadiniFile()

Something is wrong, because i got error:
LUA ERROR: sys/lua/log.lua:13: bad argument #1 to 'rename' (string expected, got
nil)

whats wrong?
To the start Previous 1 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview