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