Skip to content

Commit 38ff900

Browse files
committedMar 16, 2014
Merge pull request #152 from CiaranG/timer
Add timer() function/event (node timer based) to luacontroller
2 parents 8440d05 + 9eda62d commit 38ff900

File tree

1 file changed

+18
-7
lines changed

1 file changed

+18
-7
lines changed
 

‎mesecons_luacontroller/init.lua

+18-7
Original file line numberDiff line numberDiff line change
@@ -219,13 +219,19 @@ local getinterrupt = function(pos)
219219
return interrupt
220220
end
221221

222-
local getdigiline_send = function (pos)
223-
local digiline_send = function (channel, msg)
224-
if digiline then
225-
digiline:receptor_send(pos, digiline.rules.default, channel, msg)
226-
end
222+
local handle_timer = function(pos, elapsed)
223+
local err = lc_update(pos, {type="timer"})
224+
if err then print(err) end
225+
return false
226+
end
227+
228+
local gettimer = function(pos)
229+
local timer = function (time)
230+
if type(time) ~= "number" then return end
231+
local nodetimer = minetest.get_node_timer(pos)
232+
nodetimer:start(time)
227233
end
228-
return digiline_send
234+
return timer
229235
end
230236

231237
local create_environment = function(pos, mem, event)
@@ -239,7 +245,11 @@ local create_environment = function(pos, mem, event)
239245
pin = merge_portstates(vports, rports),
240246
port = vports,
241247
interrupt = getinterrupt(pos),
242-
digiline_send = getdigiline_send(pos),
248+
timer = gettimer(pos),
249+
digiline_msgs = {},
250+
digiline_send = function(channel, msg)
251+
table.insert(lc_digiline_msgs, {["channel"]=channel, ["msg"]=msg})
252+
end,
243253
mem = mem,
244254
tostring = tostring,
245255
tonumber = tonumber,
@@ -527,6 +537,7 @@ minetest.register_node(nodename, {
527537
if err then print(err) end
528538
reset_meta(pos, fields.code, err)
529539
end,
540+
on_timer = handle_timer,
530541
sounds = default.node_sound_stone_defaults(),
531542
mesecons = mesecons,
532543
digiline = digiline,

0 commit comments

Comments
 (0)