added var_type for storing the type of the variable (not yet used)
This commit is contained in:
parent
9856842074
commit
742ec53a6b
@ -532,9 +532,11 @@ yl_speak_up.get_fs_manage_variables = function(player, param)
|
||||
"values into this variable."
|
||||
)..add_write_button..
|
||||
"label[0.2,5.05;Type of variable: "..
|
||||
-- TODO: show actual type
|
||||
minetest.colorize("#FFFF00","String/text or numerical value, depending "..
|
||||
"on how you use it")..".]"..
|
||||
-- show variable type
|
||||
minetest.colorize("#FFFF00",
|
||||
(yl_speak_up.get_variable_metadata(k_long, "var_type")
|
||||
or "String/text or numerical value, depending on how you use it"))..
|
||||
".]"..
|
||||
"label[0.2,6.05;This variable is used by the following "..
|
||||
minetest.colorize("#FFFF00", tostring(c1)).." NPC:\n\t"..
|
||||
-- those are only n_id - no need to formspec_escape that
|
||||
@ -655,6 +657,8 @@ end
|
||||
|
||||
|
||||
-- a more general way of setting metadata for variables
|
||||
-- in general, meta_name is a table containing entries entry_name (usually players or npc_ids)
|
||||
-- with assigned values (usually true) for quick lookup
|
||||
yl_speak_up.set_variable_metadata = function(k, pname, meta_name, entry_name, new_value)
|
||||
k = yl_speak_up.add_pname_to_var(k, pname)
|
||||
-- delete/unset
|
||||
@ -669,11 +673,17 @@ yl_speak_up.set_variable_metadata = function(k, pname, meta_name, entry_name, ne
|
||||
if( not(yl_speak_up.player_vars[ k ][ "$META$" ])) then
|
||||
yl_speak_up.player_vars[ k ][ "$META$" ] = { meta_name = {} }
|
||||
end
|
||||
if( not(yl_speak_up.player_vars[ k ][ "$META$" ][ meta_name ])
|
||||
or type(yl_speak_up.player_vars[ k ][ "$META$" ][ meta_name ]) ~= "table") then
|
||||
yl_speak_up.player_vars[ k ][ "$META$" ][ meta_name ] = {}
|
||||
|
||||
-- var_type (the type of the variable) is a single string
|
||||
if(meta_name == "var_type") then
|
||||
yl_speak_up.player_vars[ k ][ "$META$"][ meta_name ] = new_value
|
||||
else
|
||||
if( not(yl_speak_up.player_vars[ k ][ "$META$" ][ meta_name ])
|
||||
or type(yl_speak_up.player_vars[ k ][ "$META$" ][ meta_name ]) ~= "table") then
|
||||
yl_speak_up.player_vars[ k ][ "$META$" ][ meta_name ] = {}
|
||||
end
|
||||
yl_speak_up.player_vars[ k ][ "$META$"][ meta_name ][ entry_name ] = new_value
|
||||
end
|
||||
yl_speak_up.player_vars[ k ][ "$META$"][ meta_name ][ entry_name ] = new_value
|
||||
yl_speak_up.save_quest_variables(true)
|
||||
return true
|
||||
end
|
||||
@ -797,6 +807,14 @@ end
|
||||
|
||||
-- which NPC do use this variable?
|
||||
yl_speak_up.get_variable_metadata = function(var_name, meta_name)
|
||||
-- var_type (the type of the variable) is a single string
|
||||
if(meta_name and var_name and meta_name == "var_type") then
|
||||
if( not(yl_speak_up.player_vars[ var_name ])
|
||||
or not(yl_speak_up.player_vars[ var_name ][ "$META$"])) then
|
||||
return nil
|
||||
end
|
||||
return yl_speak_up.player_vars[ var_name ][ "$META$"][ meta_name ]
|
||||
end
|
||||
-- no variable, or nothing stored? then it's not used by any NPC either
|
||||
if(not(var_name)
|
||||
or not(meta_name)
|
||||
|
Loading…
Reference in New Issue
Block a user