generated from your-land/yl_template
Chatcommand scheduler_add without paramater mask
This commit is contained in:
parent
b50d0fea33
commit
d0f0a5fb14
@ -1,6 +1,6 @@
|
|||||||
local chatcommand_cmd = "scheduler_add"
|
local chatcommand_cmd = "scheduler_add"
|
||||||
local chatcommand_params =
|
local chatcommand_params =
|
||||||
"<time$function$[param1, param2, param3, ...][$notes]>"
|
"<time$function$[param1, param2, param3, ...][$param mask][$notes]>"
|
||||||
local chatcommand_description =
|
local chatcommand_description =
|
||||||
"Adds a new task that executes a function with params at the given time. See /" ..
|
"Adds a new task that executes a function with params at the given time. See /" ..
|
||||||
chatcommand_cmd .. " help"
|
chatcommand_cmd .. " help"
|
||||||
|
58
internal.lua
58
internal.lua
@ -24,8 +24,7 @@ end
|
|||||||
|
|
||||||
local function is_uuid_duplicate(UUID)
|
local function is_uuid_duplicate(UUID)
|
||||||
for i, task in ipairs(yl_scheduler.tasks) do
|
for i, task in ipairs(yl_scheduler.tasks) do
|
||||||
say("action",
|
say("action", "task.id=" .. dump(task.id) .. ", UUID=" .. dump(UUID))
|
||||||
"task.id=" .. dump(task.id) .. ", UUID=" .. dump(UUID))
|
|
||||||
if task.id == UUID then return true end
|
if task.id == UUID then return true end
|
||||||
end
|
end
|
||||||
return false
|
return false
|
||||||
@ -232,13 +231,15 @@ local function load_all_tasks()
|
|||||||
|
|
||||||
if bad == 0 then
|
if bad == 0 then
|
||||||
minetest.log("action",
|
minetest.log("action",
|
||||||
"[MOD] yl_scheduler : bad = " .. tostring(bad) .. ", good = " ..
|
"[MOD] yl_scheduler : bad = " .. tostring(bad) ..
|
||||||
tostring(good) .. ", total = " .. tostring(total))
|
", good = " .. tostring(good) .. ", total = " ..
|
||||||
|
tostring(total))
|
||||||
return true, good, bad
|
return true, good, bad
|
||||||
else
|
else
|
||||||
minetest.log("warning",
|
minetest.log("warning",
|
||||||
"[MOD] yl_scheduler : bad = " .. tostring(bad) .. ", good = " ..
|
"[MOD] yl_scheduler : bad = " .. tostring(bad) ..
|
||||||
tostring(good) .. ", total = " .. tostring(total))
|
", good = " .. tostring(good) .. ", total = " ..
|
||||||
|
tostring(total))
|
||||||
return false, good, bad
|
return false, good, bad
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -305,7 +306,52 @@ function yl_scheduler.remove_file(UUID) return remove_file(UUID) end
|
|||||||
-- ### scheduler_add ###
|
-- ### scheduler_add ###
|
||||||
|
|
||||||
local function cmd_scheduler_add(name, c_params)
|
local function cmd_scheduler_add(name, c_params)
|
||||||
|
-- This is what a chatcommand may look like:
|
||||||
|
-- /scheduler_add 384756378465$minetest.log$action, text to be logged$$some notes
|
||||||
|
-- /scheduler_add 384756378465$minetest.log$action, text to be logged
|
||||||
|
-- /scheduler_add 384756378465$switch_maze
|
||||||
|
-- /scheduler_add 384756378465$switch_maze$$$some more notes
|
||||||
|
|
||||||
|
-- cast:
|
||||||
|
-- /scheduler_add 384756378465$switch_maze$(int)456, (string)mystring$some more notes
|
||||||
|
|
||||||
|
-- mask:
|
||||||
|
-- /scheduler_add 384756378465$switch_maze$456,mystring$int, string$some more notes
|
||||||
|
|
||||||
|
-- The mask should be optional, if none is given we assume strings
|
||||||
|
|
||||||
|
if not c_params or c_params == "help" then
|
||||||
|
return true,
|
||||||
|
"Adds a new task that executes a function with params at the given time.\n" ..
|
||||||
|
"Separate time, function, parameters, mask and notes with $\n" ..
|
||||||
|
"Example: /scheduler_add 1712679465$minetest.log$action,mytext$string,string$mynotes\n"
|
||||||
|
elseif c_params == "helpmask" then
|
||||||
|
return true, "Provide a parameter mask to convert the parameters to number or table" ..
|
||||||
|
"Allowed values are \"string\",\"number\",\"table\"" ..
|
||||||
|
"If your use case requires other types, please create a wrapper function."
|
||||||
|
end
|
||||||
|
|
||||||
|
local t_parameters = string.split(c_params, "$", true)
|
||||||
|
|
||||||
|
local at = tonumber(t_parameters[1])
|
||||||
|
local func = t_parameters[2]
|
||||||
|
--local string_params = string.split(t_parameters[3], ",") -- optional
|
||||||
|
local params = string.split(t_parameters[3], ",") -- optional
|
||||||
|
local mask = string.split(t_parameters[4], ",") or {} -- optional
|
||||||
|
local owner = name or "N/A"
|
||||||
|
local notes = t_parameters[5] or "" -- optional
|
||||||
|
|
||||||
|
-- local param_success, params = unmask_params(string_params, mask)
|
||||||
|
|
||||||
|
if (param_success == false) then return false, params end
|
||||||
|
|
||||||
|
local success, message = yl_scheduler.set_task(at, func, params, owner,
|
||||||
|
notes)
|
||||||
|
if success == true then
|
||||||
|
yl_scheduler.tasks = sort_by_timestamp(yl_scheduler.tasks)
|
||||||
|
end
|
||||||
|
|
||||||
|
return success, message
|
||||||
end
|
end
|
||||||
|
|
||||||
function yl_scheduler.cmd_scheduler_add(name, params)
|
function yl_scheduler.cmd_scheduler_add(name, params)
|
||||||
|
Loading…
Reference in New Issue
Block a user