Posted 14 March 2013 - 10:57 PM
Hello guys,
I started learning Lua just a week ago so please do not laugh at me if there are absurd programming defects :)/>
The last two days I spend quite a bunch of hours making my own DB Api for my Sorting System with the Interactive Sorter from MiscPeripheral.
Everything seems to work fine, but when I use my sorting script "einlesen" (the second one) CC spawns me a new DB called "nil". I know that is because of some mistake in declaring variables but I can not find the problem.
So I would appreciate it if somebody can help me out (and also for all bugfixes :rolleyes:/> )
My DB-API:
"Insert Script" aka einlesen:
P.S. Sorry for german text and variables but its a lot easier for me having "familiar words" in the beginning ^_^/>
If its better for you, I will try to translate them.
Cheers
Mirodin
I started learning Lua just a week ago so please do not laugh at me if there are absurd programming defects :)/>
The last two days I spend quite a bunch of hours making my own DB Api for my Sorting System with the Interactive Sorter from MiscPeripheral.
Everything seems to work fine, but when I use my sorting script "einlesen" (the second one) CC spawns me a new DB called "nil". I know that is because of some mistake in declaring variables but I can not find the problem.
So I would appreciate it if somebody can help me out (and also for all bugfixes :rolleyes:/> )
My DB-API:
-- variables
daten = {}
werte = {}
local pfad = "data"
-- functions
function erstellen(name) -- Creates a new DB
name = name or "data"
if not fs.exists(pfad)then
fs.makeDir(pfad)
print("Database dir created!")
end
if not fs.exists(fs.combine(pfad, name)) then
speichern(name)
if name == "data" then
print("Standard-Database \""..name.."\" created!")
else
print("Database \""..name.."\" created!")
end
end
return true
end
function laden(name) -- Loads DB
name = name or "data"
erstellen(name)
local file = fs.open(fs.combine(pfad, name), "r")
local tmp = file.readAll()
file.close()
daten = textutils.unserialize(tmp)
print("Database \""..name.."\" loaded!")
return daten
end
function speichern(name) -- Saves DB
name = name or "data"
if not fs.exists(pfad) then
erstellen(name)
end
local file = fs.open(fs.combine(pfad, name), "w")
file.write(textutils.serialize(daten))
file.close()
print("Database \""..name.."\" saved!")
end
function einfuegen(name, werte) -- Inserts new data
name = name or "data"
laden(name)
if type(werte) == "table" then
for a=1, #werte do
table.insert(daten, werte[a])
print("Item "..werte[a].." in "..name.." saved!")
end
else
table.insert(daten, werte)
print("Item "..werte.." in "..name.." saved!")
end
speichern(name)
end
"Insert Script" aka einlesen:
os.loadAPI("db")
-- Variablen
local Args = { ... }
local menge = tonumber(Args[1])
menge = menge or 1
for m=1, menge do
local event, item = os.pullEvent("isort_item")
db.einfuegen("sorter", item)
end
P.S. Sorry for german text and variables but its a lot easier for me having "familiar words" in the beginning ^_^/>
If its better for you, I will try to translate them.
Cheers
Mirodin
Edited on 15 March 2013 - 08:28 AM