- ComputerCraft | Programmable Computers for Minecraft
- → luza's Content
luza's Content
There have been 42 items by luza (Search limited from 30-March 23)
#1051 Masked Input Api
Posted by luza on 22 February 2012 - 04:12 PM in Programs
function maskedInput(pReplace) local replace = pReplace or "*" local x,y = term.getCursorPos() local input = {} term.setCursorBlink(true) while true do local event, p1 = os.pullEvent() if event == "char" then input[#input+1]=p1 write(replace) elseif event == "key" then if p1 == 28 then --enter break elseif p1 == 14 then --backspace table.remove(input) term.setCursorPos(x+#input, y) write(" ") term.setCursorPos(x+#input, y) end end end print("") term.setCursorBlink(false) return table.concat(input) end
#1046 [Forum Request] Oses & Password Locks
Posted by luza on 22 February 2012 - 03:32 PM in General
FuzzyPurp, on 20 February 2012 - 02:27 PM, said:
Here's the result!
#985 Useful Tutorials & Resources
#978 Tutorial: Creating An Api
Posted by luza on 21 February 2012 - 02:25 PM in Tutorials
Es ist ziemlich einfach ein API in Computercraft zu erstellen.
Definiere einfach die Funktionen die du in deinem API haben möchtest und speichere sie in einer Datei. Um das API zu laden benutze os.loadAPI(apiname).
Beispiel: speichere das als HBW (Halbbeständige Werte)
-- Beispiel halbbeständige Werte (speichert die werte nicht, das könntest du natürlich hinzufügen) API local data = {} -- Gibt die Versionsnummer dieses API zurück. Das kann für Entwickler sehr nützlich sein; besonders bei komplizierten APIs. function getVersion() return 0.2 end -- eine Funktion um Werte vom API zu bekommen. function getData(key) return data[key] end -- eine Funktion um Werte im API festzulegen. function setData(key, value) local oldData = data[key] data[key] = value return oldData -- es ist beim Festlegen neuer Werte immer sinnvoll die alten Werte zurückzugeben. end
#969 Table.remove Isn't Working.
Posted by luza on 21 February 2012 - 01:18 PM in Ask a Pro
function deleteLine(table, index) --expects string, number local path = getTablePath(table) local fields = {} fields = getFields(table) local file = nil local field_content = {} local file_path = nil for i=1, #fields, 1 do field_content = getField(table, fields[i]) -- everything is working until here. table.remove(field_content,index) file_path = path..fields[i] file = io.open(file_path, "w") file:write(field_content) file:close() end end
#837 Luza's Database Api
Posted by luza on 20 February 2012 - 09:43 AM in Programs
Luza's Database API
As I haven't found any nice database programs for cc yet I decided to write one myself.
I've not yet finished coding it yet (one function isn't working correct) but I think it'll be released quite soon.
Functions:
- getVersion()
- createDatabase(database)
- dropDatabase(database)
- selectDb(database)
- closeDb(database)
- createTable(table, fields)
- getTablePath(table)
- dropTable(table)
- getFields(table)
- getField(table, field)
- getLine(table, index)
- insert(table, value)
- select(table, field, like)
Functionexplanations:
getVersion()
Returns the version of the API.
createDatabase(database)
Expects a string. A new database called $database will be created.
dropDatabe(database)
Expects a string. The database $database will be deleted.
selectDb(database)
Expects a string. "opens a connection to the database $database" (not really correct but it's difficult to explain)
closeDb(database)
Expects a string. "closes the connection to the database $database" (again, not really correct)
createTable(table, fields)
Expects a string and a table. Will create a table in the database selected with selectDb() with the fields in $fields.
dropTable(table)
Expects a string. Will delete the table in the database selected with selectDb().
getFields(table)
Expects a string. Will return a table with all the fields in the table $table in the database selected in selectDb().
getField(table, field)
Expects a string and a string. Will return a table with the content of the field $field in table $table in the database selected in selectDb().
getLine(table, index)
Expects a string and a number. Will return a table with the content of the $index-th line of the table $table in the database selected in selectDb().
insert(table, value)
Expects a string and a table. Will insert the content of $value into the table $table in the database selected in selectDb().
select(table, field, like)
Expects a string, table and a table. Will return a two dimensional table containing the fields in witch $field[i] == $like[i]
As it's hard to explain here'S an example:
selectDb("luza") createTable("testtable",{"field1","field2","field3"} insert("testtable",{"test","cc","luza"}) insert("testtable",{"test","cc","peter"}) findings = select("testtable",{"field1","field2"},{"test","cc"}) print(findings[1][3]) --Output: luza print(findings[2][3]) --Output: peter
To Do:
- release it />
- add an "update" function
#834 Stop Your Program Being Terminated
Posted by luza on 20 February 2012 - 09:05 AM in Ask a Pro
And into the startupsystem you write:
while true do shell.run("check") --for "check" you write the name of your passwordsystem file. end
that would be the simpliest method.
You could also change the os.pullEvent() method but I think in your case it's not necessary.
- ComputerCraft | Programmable Computers for Minecraft
- → luza's Content