mirror of
https://git.minetest.org/BuckarooBanzay/digibuilder.git
synced 2024-12-12 00:33:21 +01:00
add examples
This commit is contained in:
parent
e5811d8d96
commit
e5f11d68c0
11
.luacheckrc
11
.luacheckrc
@ -18,3 +18,14 @@ read_globals = {
|
||||
"mesecons",
|
||||
"default"
|
||||
}
|
||||
|
||||
files["examples/"] = {
|
||||
globals = {
|
||||
"mem"
|
||||
},
|
||||
read_globals = {
|
||||
"event",
|
||||
"interrupt",
|
||||
"digiline_send"
|
||||
}
|
||||
}
|
||||
|
61
examples/simple_pattern.lua
Normal file
61
examples/simple_pattern.lua
Normal file
@ -0,0 +1,61 @@
|
||||
|
||||
-- pattern, starting at -x/-z
|
||||
local data = {
|
||||
-- x >>
|
||||
"sdsd",
|
||||
"dsds"
|
||||
-- z \/
|
||||
}
|
||||
|
||||
local nodes = {
|
||||
["s"] = "default:stone",
|
||||
["d"] = "default:dirt"
|
||||
}
|
||||
|
||||
-- coordinate offsets
|
||||
local x_offset = -10
|
||||
local y_offset = 1
|
||||
local z_offset = -10
|
||||
|
||||
-- initial start
|
||||
if event.type == "program" then
|
||||
mem.line = 1
|
||||
mem.pos = 1
|
||||
interrupt(1)
|
||||
end
|
||||
|
||||
-- timer interrupt
|
||||
if event.type == "interrupt" then
|
||||
local line = data[mem.line]
|
||||
if not line then
|
||||
-- done
|
||||
return
|
||||
end
|
||||
|
||||
local char = line[mem.pos]
|
||||
if not char then
|
||||
-- next line
|
||||
mem.line = mem.line + 1
|
||||
mem.pos = 1
|
||||
interrupt(0.5)
|
||||
return
|
||||
end
|
||||
|
||||
digiline_send("digibuilder", {
|
||||
command = "setnode",
|
||||
pos = { x=x_offset+mem.pos-1, y=y_offset, z=z_offset+mem.line-1 },
|
||||
name = nodes[char]
|
||||
})
|
||||
end
|
||||
|
||||
-- callback from digibuilder node
|
||||
if event.type == "digiline" and event.channel == "digibuilder" then
|
||||
if event.error then
|
||||
-- error state
|
||||
error(event.message)
|
||||
end
|
||||
|
||||
-- next command
|
||||
mem.line = mem.line + 1
|
||||
interrupt(1)
|
||||
end
|
40
examples/simple_schema.lua
Normal file
40
examples/simple_schema.lua
Normal file
@ -0,0 +1,40 @@
|
||||
|
||||
-- list of setnode commands
|
||||
local data = {
|
||||
{ name = "default:stone", pos = { x=1, y=0, z=1 } },
|
||||
{ name = "default:stone", pos = { x=-1, y=0, z=-1 } }
|
||||
}
|
||||
|
||||
-- initial start
|
||||
if event.type == "program" then
|
||||
mem.pos = 1
|
||||
interrupt(1)
|
||||
end
|
||||
|
||||
-- timer interrupt
|
||||
if event.type == "interrupt" then
|
||||
local entry = data[mem.pos]
|
||||
if not entry then
|
||||
-- done
|
||||
return
|
||||
end
|
||||
|
||||
digiline_send("digibuilder", {
|
||||
command = "setnode",
|
||||
pos = entry.pos,
|
||||
param2 = entry.param2,
|
||||
name = entry.name
|
||||
})
|
||||
end
|
||||
|
||||
-- callback from digibuilder node
|
||||
if event.type == "digiline" and event.channel == "digibuilder" then
|
||||
if event.error then
|
||||
-- error state
|
||||
error(event.message)
|
||||
end
|
||||
|
||||
-- next command
|
||||
mem.pos = mem.pos + 1
|
||||
interrupt(1)
|
||||
end
|
@ -46,6 +46,10 @@ if event.type == "digiline" and event.channel == "digibuilder" then
|
||||
end
|
||||
```
|
||||
|
||||
# Examples
|
||||
|
||||
For code examples for the `luacontroller` see the "examples" directory
|
||||
|
||||
# Open issues
|
||||
|
||||
* [ ] creative mode
|
||||
|
Loading…
Reference in New Issue
Block a user