experimenting with passing functions through interactions
This commit is contained in:
@ -105,29 +105,35 @@ end
|
|||||||
|
|
||||||
-- ===================================================================
|
-- ===================================================================
|
||||||
-- Function: modpol.interactions.text_query
|
-- Function: modpol.interactions.text_query
|
||||||
-- input: Query (string)
|
-- input: User (string), Query (string), func (function)
|
||||||
-- output: User response (string)
|
-- func input: user input (string)
|
||||||
function modpol.interactions.text_query(query)
|
-- output: Applies "func" to user input
|
||||||
-- TODO
|
function modpol.interactions.text_query(user, query, func)
|
||||||
|
print(user .. ": " .. query)
|
||||||
|
answer = io.read()
|
||||||
|
func(answer)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- ===================================================================
|
-- ===================================================================
|
||||||
-- Function: modpol.binary_poll_user(user, question)
|
-- Function: modpol.binary_poll_user(user, question)
|
||||||
-- Params: user (string), question (string)
|
-- Params: user (string), question (string), func (function)
|
||||||
-- Output:
|
-- func input: user input (string: y/n)
|
||||||
-- presents a yes/no/abstain poll to a user, returns answer
|
-- Output: Applies "func" to user input
|
||||||
function modpol.interactions.binary_poll_user(user, question)
|
-- presents a yes/no poll to a user, returns answer
|
||||||
|
function modpol.interactions.binary_poll_user(user, question, func)
|
||||||
local query = "Poll for " .. user .. " (y/n): ".. question
|
local query = "Poll for " .. user .. " (y/n): ".. question
|
||||||
local answer
|
local answer
|
||||||
repeat
|
repeat
|
||||||
print(query)
|
print(query)
|
||||||
answer = io.read()
|
answer = io.read()
|
||||||
until answer == "y" or answer == "n" or answer == "a"
|
until answer == "y" or answer == "n"
|
||||||
if answer == "y" then
|
if answer == "y" then
|
||||||
return "yes"
|
modpol.interactions.message(user, "Response recorded")
|
||||||
|
func("yes")
|
||||||
elseif answer == "n" then
|
elseif answer == "n" then
|
||||||
return "no"
|
modpol.interactions.message(user, "Response recorded")
|
||||||
|
func("no")
|
||||||
else
|
else
|
||||||
return "abstain"
|
modpol.interactions.message(user, "Error: invalid response")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -198,7 +198,6 @@ minetest.register_on_player_receive_fields(function (player, formname, fields)
|
|||||||
modpol.interactions.text_query(pname, "Org name:")
|
modpol.interactions.text_query(pname, "Org name:")
|
||||||
-- local new_org_name = _contexts[pname]["new_org_name"]
|
-- local new_org_name = _contexts[pname]["new_org_name"]
|
||||||
_contexts[pname] = function(input)
|
_contexts[pname] = function(input)
|
||||||
|
|
||||||
local new_request = {
|
local new_request = {
|
||||||
user = pname,
|
user = pname,
|
||||||
type = "add_org",
|
type = "add_org",
|
||||||
|
Reference in New Issue
Block a user