-- 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
ID | Author/Program | Comment | Date | |
---|---|---|---|---|
827 | #1000610 | Edit suggestion: !636 !629 main { static Object androidContext; static String programID; public static void main(String[] args) throws Exception { -- 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') }} | 2015-08-19 22:47:33 | delete |
812 | #1000604 (pitcher) | 2015-08-18 00:07:22 |
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: | 1586 / 316 |
Referenced in: | [show references] |