forked from Sokomine/yl_speak_up
added some selections for precondition 'evaluate'
This commit is contained in:
parent
58329d03a1
commit
9bbd3e943c
@ -209,9 +209,9 @@ yl_speak_up.custom_functions_a_ = {}
|
||||
yl_speak_up.custom_functions_r_ = {}
|
||||
|
||||
-- example function for preconditions:
|
||||
yl_speak_up.custom_functions_p_[ "example func" ] = {
|
||||
yl_speak_up.custom_functions_p_[ "example function" ] = {
|
||||
function_call = "yl_speak_up.custom_example_function",
|
||||
description = "Describe here in short form what your function does.",
|
||||
description = "This function is just an example. It does nothing.",
|
||||
param1_text = "1. Parameter:",
|
||||
param1_desc = "This is the value passed to the function as first parameter.",
|
||||
param2_text = "2. Parameter:",
|
||||
@ -232,10 +232,40 @@ yl_speak_up.custom_functions_p_[ "example func" ] = {
|
||||
param9_desc = "This is the value passed to the function as 9. parameter.",
|
||||
}
|
||||
|
||||
-- TODO: actually implement these as examples
|
||||
yl_speak_up.custom_functions_p_[ "set_variable_to_random_number" ] = {
|
||||
function_call = "yl_speak_up.set_variable_to_random_number",
|
||||
description = "Set a variable to a random number.",
|
||||
param1_text = "Name of the variable:",
|
||||
param1_desc = "Which variable do you want to set to a random number?",
|
||||
param2_text = "Minimum value:",
|
||||
param2_desc = "Which is the MINIMUM value the varible might be set to?",
|
||||
param3_text = "Maximum value:",
|
||||
param3_desc = "Which is the MAXIMUM value the varible might be set to?",
|
||||
}
|
||||
|
||||
yl_speak_up.custom_functions_p_[ "set_variable_to_random_value_from_list" ] = {
|
||||
function_call = "yl_speak_up.select_random_value_from_list",
|
||||
description = "Set a variable to a random value from a list.",
|
||||
param1_text = "Name of the variable:",
|
||||
param1_desc = "Which variable do you want to set to a random value from your list?",
|
||||
param2_text = "Possible values:",
|
||||
param2_desc = "Enter all the possible values/texts for your variable here.\n"..
|
||||
"Seperate the entires by \"|\", i.e.: \"entry1|entry2|entry3\".",
|
||||
}
|
||||
|
||||
|
||||
yl_speak_up.custom_functions_p_[ "get_level_of_player" ] = {
|
||||
function_call = "yl_speak_up.get_player_level",
|
||||
description = "Get the level the player has achieved.",
|
||||
}
|
||||
|
||||
|
||||
-- example function for results/effects:
|
||||
yl_speak_up.custom_functions_r_[ "example func" ] = {
|
||||
yl_speak_up.custom_functions_r_[ "example function" ] = {
|
||||
function_call = "yl_speak_up.custom_example_function",
|
||||
description = "Describe here in short form what your function does.",
|
||||
description = "This function is just an example. It does nothing.",
|
||||
param1_text = "1. Parameter:",
|
||||
param1_desc = "This is the value passed to the function as first parameter.",
|
||||
param2_text = "2. Parameter:",
|
||||
|
@ -1,7 +1,7 @@
|
||||
-- This file contains what is necessary to execute/evaluate a precondition.
|
||||
--
|
||||
-- You can add your own custom functions the file:
|
||||
-- in custrom_functions_you_can_override.lua
|
||||
-- in custom_functions_you_can_override.lua
|
||||
|
||||
-- this is called directly in yl_speak_up.get_fs_talkdialog
|
||||
-- it returns a list of options whose preconditions are fulfilled
|
||||
|
@ -231,7 +231,7 @@ yl_speak_up.save_element_p_or_a_or_e = function(
|
||||
|
||||
-- "something that has to be calculated or evaluated (=call a function)"
|
||||
elseif(what_type == "evaluate" and id_prefix ~= "a_") then
|
||||
v[ id_prefix.."value" ] = (data.evaluate or "")
|
||||
v[ id_prefix.."value" ] = (data.function_name or "")
|
||||
v[ id_prefix.."operator" ] = values_operator[ data.operator ]
|
||||
v[ id_prefix.."var_cmp_value" ] = (data.var_cmp_value or "")
|
||||
-- transfer the parameters
|
||||
@ -1033,6 +1033,14 @@ yl_speak_up.input_fs_edit_option_related = function(player, formname, fields,
|
||||
yl_speak_up.speak_to[pname][ tmp_data_cache ].property = fields.property
|
||||
end
|
||||
-- "something that has to be calculated or evaluated (=call a function)"
|
||||
if(fields.select_function_name and fields.select_function_name ~= "") then
|
||||
for k, v in pairs(yl_speak_up["custom_functions_"..id_prefix]) do
|
||||
if(v["description"] == fields.select_function_name) then
|
||||
yl_speak_up.speak_to[pname][ tmp_data_cache ].function_name = k
|
||||
end
|
||||
end
|
||||
end
|
||||
-- "something that has to be calculated or evaluated (=call a function)"
|
||||
if(fields.evaluate and fields.evaluate ~= "") then
|
||||
yl_speak_up.speak_to[pname][ tmp_data_cache ].evaluate = fields.evaluate
|
||||
end
|
||||
@ -1171,6 +1179,7 @@ yl_speak_up.input_fs_edit_option_related = function(player, formname, fields,
|
||||
or fields.store_item_name
|
||||
or fields.select_other_o_id
|
||||
or fields.select_fulfilled
|
||||
or fields.select_function_name
|
||||
or was_changed
|
||||
or fields.key_enter
|
||||
or fields.quit
|
||||
@ -1635,10 +1644,19 @@ end
|
||||
yl_speak_up.get_fs_edit_option_p_and_e_evaluate = function(
|
||||
pname, dialog, formspec, data, id_prefix, save_button, e,
|
||||
text_select_operator, values_operator, check_operator)
|
||||
local fun_list = {}
|
||||
for k, v in pairs(yl_speak_up["custom_functions_"..id_prefix]) do
|
||||
table.insert(fun_list, v["description"] or k)
|
||||
end
|
||||
table.sort(fun_list)
|
||||
local func_selected = 0
|
||||
|
||||
local func_data = nil
|
||||
if(e or true) then
|
||||
if(e) then
|
||||
--data.function_name = e[ id_prefix.."value"]
|
||||
data.function_name = "example func"
|
||||
data.function_name = e[ id_prefix.."value"]
|
||||
end
|
||||
if(data.function_name) then
|
||||
-- TODO: create the dropdown
|
||||
func_data = yl_speak_up["custom_functions_"..id_prefix][data.function_name]
|
||||
-- add the fields for param1..param9:
|
||||
@ -1664,6 +1682,8 @@ yl_speak_up.get_fs_edit_option_p_and_e_evaluate = function(
|
||||
end
|
||||
end
|
||||
end
|
||||
func_selected = table.indexof(fun_list,
|
||||
yl_speak_up["custom_functions_"..id_prefix][data.function_name]["description"])
|
||||
end
|
||||
local operator_list = {}
|
||||
for i, v in ipairs(check_operator) do
|
||||
@ -1679,14 +1699,14 @@ yl_speak_up.get_fs_edit_option_p_and_e_evaluate = function(
|
||||
data, id_prefix, save_button, e,
|
||||
values_operator, operator_list, "function",
|
||||
"Execute and evaluate the following function:",
|
||||
text_select_operator, "Compare the return value with this value:")
|
||||
"Operator for checking result:", "Compare the return value with this value:")
|
||||
end
|
||||
-- the list of available variables needs to be extended with the ones
|
||||
return formspec..
|
||||
text_operator_and_comparison..
|
||||
-- TODO: rather a dropdown...
|
||||
"field[1.0,4.8;5.0,0.6;property;;"..
|
||||
minetest.formspec_escape(data.property or "- enter name -").."]"
|
||||
"dropdown[0.2,4.8;6.5,0.6;select_function_name;"..
|
||||
"- please select -,"..table.concat(fun_list, ",")..";"..
|
||||
tostring(func_selected + 1)..";]"
|
||||
-- "hypertext[1.2,7.0;16.0,2.5;some_text;<normal>"..
|
||||
-- "<b>Note:</b> Functions are called with parameters which are passed on to them. "..
|
||||
-- "The function then calculates a result. This can be compared to a given value."..
|
||||
|
Loading…
Reference in New Issue
Block a user