Closed BrunoMine closed 6 years ago
Taking advantage, is there any way to check if the npc is resting?
self.actions.move_state.is_laying
not work.
Regarding your first comment: you can enqueue programs using:
npc.exec.enqueue_program(self, program_name, arguments, interrupt_options)
where arguments
and interrupt_options
are tables.
Regarding second comment: that variable is now self.npc_state.movement.is_laying
I would like to suggest you about interrupt_options
. While this is important, we can make this less trivial for a first encodiing, even because this is irrelevant to some short programs.
If it is missing, it can cause crashes. Can you make this optional?
2018-04-19 11:08:44: ERROR[Main]: ServerError: AsyncErr: ServerThread::run Lua: Runtime error from mod 'sunos' in callback luaentity_Step(): ...Mods/minetest 0-5-0/bin/../mods/advanced_npc/npc.lua:790: bad argument #1 to 'next' (table expected, got nil)
2018-04-19 11:08:44: ERROR[Main]: stack traceback:
2018-04-19 11:08:44: ERROR[Main]: [C]: in function 'next'
2018-04-19 11:08:44: ERROR[Main]: ...Mods/minetest 0-5-0/bin/../mods/advanced_npc/npc.lua:790: in function 'create_interrupt_options'
2018-04-19 11:08:44: ERROR[Main]: ...Mods/minetest 0-5-0/bin/../mods/advanced_npc/npc.lua:839: in function 'create_process_entry'
2018-04-19 11:08:44: ERROR[Main]: ...Mods/minetest 0-5-0/bin/../mods/advanced_npc/npc.lua:990: in function 'priority_enqueue'
2018-04-19 11:08:44: ERROR[Main]: ...Mods/minetest 0-5-0/bin/../mods/advanced_npc/npc.lua:1717: in function 'execution_routine'
2018-04-19 11:08:44: ERROR[Main]: ...Mods/minetest 0-5-0/bin/../mods/advanced_npc/npc.lua:2155: in function <...Mods/minetest 0-5-0/bin/../mods/advanced_npc/npc.lua:2075>
2018-04-19 11:08:44: ERROR[Main]: (tail call):
Pushed change to allow nil
interrupt_options
argument, didn't tested but I guess it should work 8f159a94789838147512dba344dcd8b6eef17bbd
Something changed in Schedule query/check definition? Or now you use a program state?
{
check = true, -- Indicates that this is a schedule query/check
range = 2, -- Range of checked area in blocks.
count = 20, -- How many checks will be performed.
random_execution_times = true, --[[
^ Randomizes the number of checks that will be performed.
^ min_count and max_count is required ]]
min_count = 20, -- minimum of checks
max_count = 25, -- maximum of checks
nodes = {"itemstring1", "itemstring2"}, --[[
^ Nodes to be found for the actions.
^ When a node is found, it is add in the npc place map
with the place name "schedule_target_pos"
prefer_last_acted_upon_node = true, -- If prefer to act on nodes already acted upon
walkable_nodes = {"itemstring1", "itemstring2"}, -- Walkable nodes
actions = { --[[
^ Table where index is a itemstring of the node to be found,
and value is an array of actions and tasks to be performed
when found the node. ]]
["itemstring1"] = {
[1] = action or task in schedule command format,
[2] = action or task in schedule command format,
[3] = action or task in schedule command format
},
["itemstring2"] = {
[1] = action or task in schedule command format,
[2] = action or task in schedule command format
}
},
}
Schedule query/check is not supported anymore. It can be easily implemented as a program which makes it more flexible... I have been thinking to actually implement it but not sure. What are your thoughts on this?
Well, I think there must be a program that does this, eventually we will have one program (or a sequence of programs) within another. Optionally it can run continuously while the queue is empty or for just some times. I currently use this to define interactions into a house, it's similar to plantation, but every object in the house has a different interaction.
Ok, sounds good! I guess I will implement a advanced_npc:node_query
which does this, and can be run as a state program (which means will be continously enqueued when queue is empty). I had been thinking on doing it but was not sure... will do it.
Thanks, this is a very important tool to summarize a ton of codes.
I have started implementation of node_query
program. There will be some changes. What used to be "actions" and "none_actions" will only support programs. So, for example, in the case of the farmer, instead of "actions" being:
There will be a program that will execute these instructions.
I look forward to start testing.
Implemented advanced_npc:node_query
(55fb139d9003b02e2797d786953ab6c135558235). Still WIP though, not tested fully the execution count and for some reasons sometimes it just stops running and switches to other state process.
For idea on how to use, look at https://github.com/hkzorman/advanced_npc/blob/commands_api/data/occupations/default_farmer.lua
Ok, I'll start testing and reporting errors found (and maybe a solution).
And this way does not allow you to queue multiple programs, apparently it runs all at once.