hkzorman / advanced_npc

Advanced NPC for Minetest, using mobs_redo API
Other
17 stars 5 forks source link

index local state_program_on_finished (a nil value) #41

Closed BrunoMine closed 6 years ago

BrunoMine commented 6 years ago

I allowed to see the arguments to help.

2018-04-23 13:08:35: [Server]: [advanced_npc] INFO: Hi, executing state process "advanced_npc:node_query"
2018-04-23 13:08:35: [Server]: [advanced_npc] INFO: Executing program '"advanced_npc:node_query"' with args:
{
    prefer_last_acted_upon_node = false,
    count = 1,
    nodes = {
        "sunos:bau_casa",
        "default:furnace",
        "sunos:wood_barrel_nodrop",
        "sunos:tear_palha_nodrop",
        "sunos:bancada_de_trabalho_nodrop",
        "sunos:kit_culinario_nodrop"
    },
    range = 6,
    on_found_executables = {
        ["sunos:wood_barrel_nodrop"] = {
            {
                program_name = "advanced_npc:walk_to_pos",
                arguments = {
                    end_pos = "compostagem"
                },
                interrupt_options = {

                }
            },
            {
                program_name = "advanced_npc:wait",
                arguments = {
                    time = 3
                }
            }
        },
        ["sunos:bau_casa"] = {
            {
                program_name = "advanced_npc:walk_to_pos",
                arguments = {
                    end_pos = "bau"
                },
                interrupt_options = {

                }
            },
            {
                program_name = "advanced_npc:wait",
                arguments = {
                    time = 3
                }
            }
        },
        ["sunos:tear_palha_nodrop"] = {
            {
                program_name = "advanced_npc:walk_to_pos",
                arguments = {
                    end_pos = "tear"
                },
                interrupt_options = {

                }
            },
            {
                program_name = "advanced_npc:wait",
                arguments = {
                    time = 3
                }
            }
        },
        ["sunos:kit_culinario_nodrop"] = {
            {
                program_name = "advanced_npc:walk_to_pos",
                arguments = {
                    end_pos = "kit_culinario"
                },
                interrupt_options = {

                }
            },
            {
                program_name = "advanced_npc:wait",
                arguments = {
                    time = 2
                }
            }
        },
        ["sunos:bancada_de_trabalho_nodrop"] = {
            {
                program_name = "advanced_npc:walk_to_pos",
                arguments = {
                    end_pos = "bancada_de_trabalho"
                },
                interrupt_options = {

                }
            },
            {
                program_name = "advanced_npc:wait",
                arguments = {
                    time = 1
                }
            }
        },
        ["default:furnace"] = {
            {
                program_name = "advanced_npc:walk_to_pos",
                arguments = {
                    end_pos = "furnace_primary"
                },
                interrupt_options = {

                }
            },
            {
                program_name = "advanced_npc:wait",
                arguments = {
                    time = 5
                }
            }
        }
    },
    on_not_found_executables = {
        {
            program_name = "advanced_npc:walk_to_pos",
            arguments = {
                end_pos = "bau"
            },
            interrupt_options = {

            }
        },
        {
            program_name = "advanced_npc:wait",
            arguments = {
                time = 3
            }
        }
    }
}
2018-04-23 13:08:35: ERROR[Main]: ServerError: AsyncErr: ServerThread::run Lua: Runtime error from mod 'sunos' in callback luaentity_Step(): ...anced_npc/executable/programs/builtin/node_query.lua:220: attempt to index local 'state_program_on_finished' (a nil value)
2018-04-23 13:08:35: ERROR[Main]: stack traceback:
2018-04-23 13:08:35: ERROR[Main]:   ...anced_npc/executable/programs/builtin/node_query.lua:220: in function <...anced_npc/executable/programs/builtin/node_query.lua:8>
2018-04-23 13:08:35: ERROR[Main]:   (tail call): ?
2018-04-23 13:08:35: ERROR[Main]:   ...Mods/minetest 0-5-0/bin/../mods/advanced_npc/npc.lua:911: in function 'execute_process'
2018-04-23 13:08:35: ERROR[Main]:   ...Mods/minetest 0-5-0/bin/../mods/advanced_npc/npc.lua:1168: in function 'process_scheduler'
2018-04-23 13:08:35: ERROR[Main]:   ...Mods/minetest 0-5-0/bin/../mods/advanced_npc/npc.lua:1324: in function 'execution_routine'
2018-04-23 13:08:35: ERROR[Main]:   ...Mods/minetest 0-5-0/bin/../mods/advanced_npc/npc.lua:1910: in function <...Mods/minetest 0-5-0/bin/../mods/advanced_npc/npc.lua:1833>
2018-04-23 13:08:35: ERROR[Main]:   (tail call): ?
2018-04-23 13:08:35: ERROR[Main]:   ...de Mods/minetest 0-5-0/bin/../mods/mobs_redo/api.lua:2579: in function <...de Mods/minetest 0-5-0/bin/../mods/mobs_redo/api.lua:2522>
2018-04-23 13:08:35: ACTION[Server]: 888 leaves game. List of players:
BrunoMine commented 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
BrunoMine commented 6 years ago

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.

hkzorman commented 6 years ago

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.
BrunoMine commented 6 years ago

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.

hkzorman commented 6 years ago

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.

BrunoMine commented 6 years ago

Yes, but this concept was fundamental to get here. Congratulations.

hkzorman commented 6 years ago

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.

hkzorman commented 6 years ago

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)

hkzorman commented 6 years ago

Latest commit (331eb248cfcdbe9b6025e3bad9bcbce8ccabbc6f) should fix the issue regarding state process switching (mentioned here https://github.com/hkzorman/advanced_npc/issues/40#issuecomment-383405563)

BrunoMine commented 6 years ago

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.

BrunoMine commented 6 years ago

Thanks.

hkzorman commented 6 years ago

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:

BrunoMine commented 6 years ago

I'll attach this all in the documentation, it might be useful.