added code_input_handler for actions of type "evaluate"
This commit is contained in:
parent
3cd6077efd
commit
48e5af991c
@ -294,7 +294,19 @@ yl_speak_up.custom_functions_a_[ "example function" ] = {
|
||||
"label[0.5,8.0;It is up to the custom function to make whatever sense it wants "..
|
||||
"\nout of these parameters.]"
|
||||
end,
|
||||
-- TODO: function for evaluating the input
|
||||
-- this function will be called by the one that handles all custom input to actions
|
||||
-- of the type "evaluate"; it can change the value of entries of the table "fields"
|
||||
-- if necessary
|
||||
code_input_handler = function(player, n_id, a, formname, fields)
|
||||
local pname = player:get_player_name()
|
||||
-- let's just tell the player the value of "fields" (after all this is an
|
||||
-- example function)
|
||||
minetest.chat_send_player(pname, "The custom action input handler \""..
|
||||
minetest.formspec_escape(tostring(a.a_value)).."\" was called with "..
|
||||
"the following input:\n"..minetest.serialize(fields))
|
||||
-- the function has to return fields
|
||||
return fields
|
||||
end,
|
||||
}
|
||||
|
||||
|
||||
|
@ -696,14 +696,23 @@ end
|
||||
|
||||
-- action of the type "evaluate"
|
||||
yl_speak_up.input_fs_action_evaluate = function(player, formname, fields)
|
||||
-- TODO: handle custom functions
|
||||
local pname = player:get_player_name()
|
||||
local a_id = yl_speak_up.speak_to[pname].a_id
|
||||
-- the custom input_handler may have something to say here as well
|
||||
local a = yl_speak_up.get_action_by_player(player)
|
||||
if(player and a and a.a_value) then
|
||||
local custom_data = yl_speak_up.custom_functions_a_[a.a_value]
|
||||
if(custom_data and custom_data.code_input_handler) then
|
||||
local fun = custom_data.code_input_handler
|
||||
-- actually call the function (which may change the value of fields)
|
||||
fields = fun(player, n_id, a, formname, fields)
|
||||
end
|
||||
end
|
||||
-- back from error_msg? then show the formspec again
|
||||
if(fields.back_from_error_msg) then
|
||||
yl_speak_up.show_fs(player, "action_evaluate", nil)
|
||||
return
|
||||
end
|
||||
local pname = player:get_player_name()
|
||||
local a_id = yl_speak_up.speak_to[pname].a_id
|
||||
if(fields.back_to_talk) then
|
||||
-- the action was aborted
|
||||
yl_speak_up.execute_next_action(player, a_id, nil)
|
||||
@ -732,6 +741,7 @@ end
|
||||
yl_speak_up.get_fs_action_evaluate = function(player, param)
|
||||
local pname = player:get_player_name()
|
||||
local dialog = yl_speak_up.speak_to[pname].dialog
|
||||
local n_id = yl_speak_up.speak_to[pname].n_id
|
||||
local a = yl_speak_up.get_action_by_player(player)
|
||||
if(not(a)) then
|
||||
return ""
|
||||
|
Loading…
Reference in New Issue
Block a user