Closed BrunoMine closed 6 years ago
Maybe you can turn optional with
-- Check if max number of executions was reached
if execution_count > times_to_execute and state_program_on_finished then
npc.exec.set_state_program(self,
state_program_on_finished.program_name,
state_program_on_finished.arguments,
state_program_on_finished.interrupt_option)
end
In this case, if it is already a program_state, it is not necessary to declare another, otherwise it would become an eternal loop. But the idea sounds very good, so make it optional. I need to include it in the documentation.
This is my fault :S I already coded fix but has not pushed yet.
Simply add to the arguments?of advanced_npc:node_query
:
program_name = "advanced_npc:idle",
arguments = {}
}```
It is required only if you pass count or randomize de number of execution times. Reason is because once it is over, it needs to apply a new state program.
I understand, but I like to make the node_query itself a state_program. That keeps him working until the next schedule. In this case I do not want it to simply stop after a specific number of checks, I want to keep it until the next schedule time, where a new task will be added to the queue, closing the node_query.
Got you, and yes, that makes sense. I actually don't like a lot the number of execution times, this was a concept when it was part of schedules as there it needed to have some way to stop.
I will make it optional.
Yes, but this concept was fundamental to get here. Congratulations.
Pushed commit to make it optional: 992c06c5b2f996f2b129ba010b1adefc7c5a1c35
Thanks. Yes it was actually the schedule check which made me unhappy on how limited the API was... I think it is very flexible as it is now.
Also, please note that this part of your code:
program_name = "advanced_npc:wait",
arguments = {
time = 3
}
isn't ok. advanced_npc:wait
is an instruction, not a program, therefore doing that will do nothing (it will try to execute an unknown program).
That's why on previous thread I mentioned it would only support programs... meaning you have to register your own program to handle each node (or register just one program and handle all nodes on it, as I do on default_farmer
:(https://github.com/hkzorman/advanced_npc/blob/992c06c5b2f996f2b129ba010b1adefc7c5a1c35/data/occupations/default_farmer.lua#L29)
Latest commit (331eb248cfcdbe9b6025e3bad9bcbce8ccabbc6f) should fix the issue regarding state process switching (mentioned here https://github.com/hkzorman/advanced_npc/issues/40#issuecomment-383405563)
I've noticed that "advanced_npc:wait"
is wrong, semantically it should be part of a program and that makes sense. I still need to learn how program registrarion works essentially.
Thanks.
Programs registration is really easy, it is just a Lua function.
There are many examples of programs, but the general approach to writing one is:
advanced_npc:interrupt
npc.exec.var*
functions)I'll attach this all in the documentation, it might be useful.
I allowed to see the arguments to help.