PtokaX forum

Archive => Archived 4.0 boards => Help with Lua 4 scripts => Topic started by: Themaster on 20 October, 2004, 16:30:13

Title: About ini
Post by: Themaster on 20 October, 2004, 16:30:13
if i want to make my script so that the .ini are where it change the settings in my script have can i do that

like this in my ini

Word = 1   --1 allow or 0 disallow

i will made so that it can turn on or off

ect

Title:
Post by: Herodes on 20 October, 2004, 19:10:25
As always there are two ways ...

1. Simple :

use dofile("filename.ini") to load up the variables and their values in the memory

Advantages :
-- Simple to use ..

Disadvantages :
-- you cant save any settings
unless by editing the file directly
-- You may not find the file where you are looking for it ..
to solve this use assert(condition, error_message)
assert Example :
assert( 1==1 , "One is not one")
-- this will be ok because 1 is equal to 1
assert( 1==2, "One is not one")
-- this will issue a message "One is not one" in the debug/error output...
so if dofile returns ' nil ' which isnt ' true ' then assert will catch it and inform about the errror ...
Common use :file = "filename.txt"
assert(dofile(file), "ERROR!!, "..file.." wasn't found..")

2. Complicated :
The complicated way involves using some sort of saveToFile* function that stores the values in the file ... overwriting contents if the exist in the file previously ...

* Look for Serialize, pickle ...  in here there are Lua4 versions of those ... Clients can use Lua 5 pickle function look for ' libsimplepickle.lua ' in the scripts folder ...
Title:
Post by: Themaster on 20 October, 2004, 19:53:40
i Cant get it work write... i do have this in my ini file there shoot be 1 allow or 0 disallow

replaced = 0 -- 1 Allow or 0 Disallow