minetest-LOTR / Lord-of-the-Test

LOTR-inspired Subgame for Minetest. Rewrite: https://github.com/minetest-LOTR/Third-Age
Other
67 stars 31 forks source link

lottthrowing crash #190

Open MoNTE48 opened 1 year ago

MoNTE48 commented 1 year ago
2023-07-16 05:58:37: ERROR[Main]: ServerError: AsyncErr: ServerThread::run Lua: Runtime error from mod 'lottthrowing' in callback luaentity_Step(): ...n/../games/lordofthetest/mods/lottthrowing/arrow.lua:120: attempt to index field 'player' (a nil value)
2023-07-16 05:58:37: ERROR[Main]: stack traceback:
2023-07-16 05:58:37: ERROR[Main]:   ...n/../games/lordofthetest/mods/lottthrowing/arrow.lua:120: in function <...n/../games/lordofthetest/mods/lottthrowing/arrow.lua:84>
MoNTE48 commented 1 year ago
- if self.player ~= "" then
+ if self.player and self.player:is_player() then
lumidify commented 1 year ago

Hi,

Thanks for the bug report. I was about to commit your fix, but I think there's more to the bug than meets the eye at first. If you look in the function lottthrowing_shoot_arrow in init.lua, the field player of the placed entity is set to the actual ObjectRef of the player, which is probably not the sensible thing to do here (and then it doesn't make any sense to compare player to ""). I'm assuming that this should actually be set to the name of the player instead. Then the on_step callback in arrow.lua can use minetest.get_player_by_name to get the actual player.

@neinwhal thoughts?

MoNTE48 commented 1 year ago

@lumidify, that's a good point. I suggested a simple fix given that LOTT is in maintenance mode. But I'm always in favor of a more proper and clean way of doing things.

neinwhal commented 1 year ago

good eye, yeah, the logic is broken. seems like a lazy attempt by me 7 years back to attempt to get mob detection for arrows; https://github.com/minetest-LOTR/Lord-of-the-Test/commit/44c16f7442636b7a6586e4776f6acfef4add9274 I should probably look through the rest of outdated code to spot for any other broken logic as well...