Fix controller stop command bug
This commit is contained in:
parent
d8caf09cf7
commit
d5c63a8e56
@ -398,26 +398,28 @@ end
|
|||||||
local function call_loop(pos, meta, elapsed)
|
local function call_loop(pos, meta, elapsed)
|
||||||
local t = minetest.get_us_time()
|
local t = minetest.get_us_time()
|
||||||
local number = meta:get_string("number")
|
local number = meta:get_string("number")
|
||||||
if Cache[number] or compile(pos, meta, number) then
|
if meta:get_int("running") == STATE_RUNNING then
|
||||||
local cpu = meta:get_int("cpu") or 0
|
if Cache[number] or compile(pos, meta, number) then
|
||||||
local code = Cache[number].code
|
local cpu = meta:get_int("cpu") or 0
|
||||||
local res = safer_lua.run_loop(pos, elapsed, code, error)
|
local code = Cache[number].code
|
||||||
if res then
|
local res = safer_lua.run_loop(pos, elapsed, code, error)
|
||||||
-- Don't count thread changes
|
if res then
|
||||||
t = math.min(minetest.get_us_time() - t, 1000)
|
-- Don't count thread changes
|
||||||
cpu = math.floor(((cpu * 20) + t) / 21)
|
t = math.min(minetest.get_us_time() - t, 1000)
|
||||||
meta:set_int("cpu", cpu)
|
cpu = math.floor(((cpu * 20) + t) / 21)
|
||||||
meta:set_string("infotext", "Controller "..number..": running ("..cpu.."us)")
|
meta:set_int("cpu", cpu)
|
||||||
if not update_battery(meta, cpu) then
|
meta:set_string("infotext", "Controller "..number..": running ("..cpu.."us)")
|
||||||
no_battery(pos)
|
if not update_battery(meta, cpu) then
|
||||||
return false
|
no_battery(pos)
|
||||||
|
return false
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
-- further messages available?
|
||||||
|
if next(Cache[number].inputs["msg"]) then
|
||||||
|
minetest.after(1, call_loop, pos, meta, -1)
|
||||||
|
end
|
||||||
|
return res
|
||||||
end
|
end
|
||||||
-- further messages available?
|
|
||||||
if next(Cache[number].inputs["msg"]) then
|
|
||||||
minetest.after(1, call_loop, pos, meta, -1)
|
|
||||||
end
|
|
||||||
return res
|
|
||||||
end
|
end
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user