mirror of
https://gitea.your-land.de/Sokomine/yl_speak_up.git
synced 2025-06-21 06:38:02 +02:00
finished implementation of effect "evaluate"
This commit is contained in:
parent
dae9e308b4
commit
7deca89a5d
@ -294,6 +294,20 @@ yl_speak_up.custom_functions_r_[ "example function" ] = {
|
||||
param8_desc = "This is the value passed to the function as 8. parameter.",
|
||||
param9_text = "9. Parameter:",
|
||||
param9_desc = "This is the value passed to the function as 9. parameter.",
|
||||
-- the actual implementation of the function
|
||||
code = function(player, n_id, r)
|
||||
local pname = player:get_player_name()
|
||||
local str = ""
|
||||
for i = 1,9 do
|
||||
str = str.."\n\tParameter "..tostring(i)..": "..tostring(r["r_param"..tostring(i)])
|
||||
end
|
||||
minetest.chat_send_player(pname, "Checking effect "..tostring(r.r_id)..
|
||||
" for NPC with ID "..tostring(n_id)..": Executing custom function "..
|
||||
tostring(r.r_value).." with the following parameters:"..
|
||||
str.."\n(This function just tells you its parameters and returns true.)")
|
||||
-- the function was successful (effects only return true or false)
|
||||
return true
|
||||
end,
|
||||
}
|
||||
|
||||
-----------------------------------------------------------------------------
|
||||
|
@ -530,8 +530,16 @@ yl_speak_up.execute_effect = function(player, n_id, o_id, r)
|
||||
return true
|
||||
-- "something that has to be calculated or evaluated (=call a function)", -- evaluate
|
||||
elseif(r.r_type == "evaluate") then
|
||||
-- TODO
|
||||
return true
|
||||
if(not(player) or not(r.r_value)) then
|
||||
return false
|
||||
end
|
||||
local custom_data = yl_speak_up.custom_functions_r_[r.r_value]
|
||||
if(not(custom_data) or not(custom_data.code)) then
|
||||
return false
|
||||
end
|
||||
local fun = custom_data.code
|
||||
-- actually call the function
|
||||
return fun(player, n_id, r)
|
||||
-- "a block somewhere" -- 3
|
||||
elseif(r.r_type == "block") then
|
||||
-- is the position given correctly?
|
||||
|
@ -224,7 +224,7 @@ yl_speak_up.show_effect = function(r, pname)
|
||||
elseif(r.r_type == "evaluate") then
|
||||
local str = ""
|
||||
for i = 1, 9 do
|
||||
str = str..tostring(p["r_param" + str(i)])
|
||||
str = str..tostring(r["r_param"..tostring(i)])
|
||||
if(i < 9) then
|
||||
str = str..","
|
||||
end
|
||||
|
@ -1719,12 +1719,32 @@ yl_speak_up.get_fs_edit_option_p_and_e_evaluate = function(
|
||||
end
|
||||
end
|
||||
local text_operator_and_comparison = ""
|
||||
local explanation = ""
|
||||
local dlength = "6.5"
|
||||
if(id_prefix ~= "r_") then
|
||||
text_operator_and_comparison = yl_speak_up.get_fs_operator_based_comparison(
|
||||
data, id_prefix, save_button, e,
|
||||
values_operator, operator_list, "function",
|
||||
"Execute and evaluate the following function:",
|
||||
"Operator for checking result:", "Compare the return value with this value:")
|
||||
explanation =
|
||||
"<b>Note:</b> Functions are called with parameters which are passed on to them. "..
|
||||
"The function then calculates a result. This result can be compared to a given "..
|
||||
"value. What the function calculates and what it returns depends on its "..
|
||||
"implementation."
|
||||
else
|
||||
dlength = "15" -- we have more room for the dropdown here
|
||||
if(not(data["function"]) or data["function"]=="") then
|
||||
save_button = ""
|
||||
end
|
||||
text_operator_and_comparison =
|
||||
"label[0.2,3.3;Execute the following function:]"..
|
||||
"label[0.2,4.3;Name of function:]"..
|
||||
save_button
|
||||
explanation =
|
||||
"<b>Note:</b> Functions are called with parameters which are passed on to them. "..
|
||||
"Functions used as effects/results ought to change something, i.e. set a "..
|
||||
"variable to a new value."
|
||||
end
|
||||
-- the list of available variables needs to be extended with the ones
|
||||
return formspec..
|
||||
@ -1732,14 +1752,11 @@ yl_speak_up.get_fs_edit_option_p_and_e_evaluate = function(
|
||||
-- show the description of the function again (the space in the dropdown menu is a bit
|
||||
-- limited)
|
||||
"label[7.5,3.3;"..minetest.formspec_escape(add_description).."]"..
|
||||
"dropdown[0.2,4.8;6.5,0.6;select_function_name;"..
|
||||
"dropdown[0.2,4.8;"..dlength..",0.6;select_function_name;"..
|
||||
"- please select -,"..table.concat(fun_list, ",")..";"..
|
||||
tostring(func_selected + 1)..";]"..
|
||||
"hypertext[1.2,9.6;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 result can be compared to a given "..
|
||||
"value. What the function calculates and what it returns depends on its "..
|
||||
"implementation."..
|
||||
explanation..
|
||||
"</normal>]"
|
||||
end
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user