-- a bot that can be turned on and off. and report its status.
function loadFunctionOnInput(sID)
local env = {}
setmetatable(env, {__index=function(o, k) return _G[k] end })
assert(input, 'no input')
assert(_G.input, 'no input in _G')
assert(env.input, 'no input in sub-env')
return assert(loadSnippet(sID, env))
end
function loadOneArgFunction(sID)
local env = {}
setmetatable(env, {__index=function(o, k) return _G[k] end })
local f = assert(loadSnippet(sID, env))
f()
for k, v in pairs(env) do
if type(v) == 'function' then
return v
end
end
error('no function found in '..sID)
end
is_TURN_ON = loadFunctionOnInput("#55")
is_TURN_OFF = loadFunctionOnInput("#56")
is_ARE_YOU_ON = loadFunctionOnInput("#62")
renderIntention = loadOneArgFunction("#63")
if is_TURN_ON() then
state.on = true
elseif is_TURN_OFF() then
state.on = false
elseif is_ARE_YOU_ON() then
-- proceed
else
return ''
end
return renderIntention(state.on and 'I AM ON' or 'I AM OFF')
test run test run with input download show line numbers
Travelled to 12 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt
2 comment(s) hidden. show
| Recognizer | Recognition Result | Visualize | Recalc |
|---|---|---|---|
| #308 | 1046 | [visualize] |
| Snippet ID: | #61 |
| Snippet name: | ON/OFF BOT |
| Eternal ID of this version: | #61/1 |
| Text MD5: | 568b46a4420eb70b3e6a1c8955494c5a |
| Author: | stefan |
| Category: | bots |
| Type: | Lua code |
| Public (visible to everyone): | Yes |
| Archived (hidden from active list): | No |
| Created/modified: | 2013-12-31 20:43:50 |
| Source code size: | 1046 bytes / 41 lines |
| Pitched / IR pitched: | Yes / Yes |
| Views / Downloads: | 2325 / 439 |
| Referenced in: | [show references] |