First, I would remove the spaces in the entries, as they're kind of pointless and make it slightly more difficult to read from the file. In order to read the entries, you'll need to use a string-split function. None exists currently (as far as I know), so you'll have to write one using string.sub(line, string.find(line, ":") or something like that.
Using that, you can simply iterate over every line in the file, checking for the entry you're looking for (again, with the string-split function), then saving the value to a variable.
(This may or may not be the best method. Either way, it works for me.)
As for encryption and decryption: pointless, since reading the code of a program is trivial. You'd be better off using a hash.
So if I used:
string.sub(line, string.find(line, ":")that would not split the string, it would merely remove the colon, yes? Would I have to iterate every letter on the line, save it to a table, find a colon, reiterate through the table and move everything before colon to a new table, build it back as a string, and save it as the variable, then rinse-repeat with the value of that variable?
o.O I thought lua was an easy language.
string.find(string, mark) returns the first index of mark in string. So if you have a string "variable:value", then calling string("variable:value", ":") should return 9.
string.sub(string, pos) returns a substring of string where pos is the starting value. So if you call string.sub("variable:value", 10), you should get "value".
I think I might be off by a number or two, but that's the general idea for return the value of an entry.
file = fs.open("database", "r")
while true do
line = fs.readLine()
if string.sub(line, 1, string.find(line, ":")) == "lastZ" then
lastZ = string.sub(line.."", string.find(line, ":") + 1)
end
end
The code might not work, but it's the general idea. Read the Lua documentation to learn more about string.sub() and string.find().