DoyleChris wrote:I received this error when i went to rename one of the saved files.
Code: Select all
2019-08-13 18:03:22: ERROR[Main]: ServerError: AsyncErr: ServerThread::run Lua: Runtime error from mod 'vbots' in callback on_playerReceiveFields(): ...GB/minetest/bin/../mods/visual-bots/formspec_handler.lua:157: attempt to index local 'bot_data' (a nil value)
2019-08-13 18:03:22: ERROR[Main]: stack traceback:
2019-08-13 18:03:22: ERROR[Main]: ...GB/minetest/bin/../mods/visual-bots/formspec_handler.lua:157: in function <...GB/minetest/bin/../mods/visual-bots/formspec_handler.lua:13>
2019-08-13 18:03:22: ERROR[Main]: /mnt/700GB/minetest/bin/../builtin/game/register.lua:419: in function </mnt/700GB/minetest/bin/../builtin/game/register.lua:399>
The reset switch works well thank you.
Another idea if possible be able to rename bot.
Nigel wrote:I've never seen that error, and can't seem to reproduce it. I can see what the problem is, but am baffled as to how the situation came to be.
Still, I've updated the code in a way which should stop the situation happening.
Enjoy.
I'm not sure, but it might be due to
bot_rekey() setting the
bot_key to nil and creating an
inconsistency when
register_on_player_receive_fields is called.
EG: when
form_parts[2] is used to get the
bot_data, was for the formspec updated to reference
new_key ?
If the
bot_key referenced the
old key then it would definitely make
bot_data nil, since it does not exist.
It is also possible that
bot_key contained no commas which would make
form_parts[2] nil, which would result in the same as above --
bot_data is nil.
Also, when acquring
bot_data, and it is nil, it might be a good idea to print/log and error that the reference
bot_key could not be located.
https://github.com/nyje/visual-bots/blo ... andler.lua
Code: Select all
-------------------------------------
-- generate new key & move data in table
-------------------------------------
local function bot_rekey(bot_key,meta)
local new_key = vbots.get_key()
vbots.bot_info[new_key] = vbots.bot_info[bot_key]
vbots.bot_info[bot_key] = nil
meta:set_string("key", new_key)
return new_key
end
line 78: local form_parts = string.split(bot_key,",")
-- updated to this to ensure that bot_key contains a comma before
-- attempting to split, still need to check the length of form_parts
local form_parts = { bot_key }
if string.match(form_parts, ",") then
form_parts = string.split(bot_key,",")
end
-- no check that form_parts[2] is not nil or an empty string, need to check the length before using it
if form_parts[2] == nil or form_parts[2] == "" then
-- log message
return
end
if table.getn(form_parts) < 2 then
-- log message
return
end
line 156: local bot_data = vbots.bot_info[form_parts[2]]
line 156.5: if bot_data == nil then print("Could not find bot_key ['" .. bot_key .. "']") return end
line 157: local pos=bot_data.pos