GunTurretAlerts

by unhott

Adds map alerts for players when a turret is either out of ammo or has low ammo

Utilities
5 years ago
0.16 - 0.17
22

b Crash due to LuaItemStack not being valid_for_read

5 years ago

I've been playing around with the turret prototypes, and I've created a turret with more than one inventory slot. I suspect that it crashes when the first inventory slot is empty.

561.788 Error MainLoop.cpp:1173: Exception at tick 770400: The mod GunTurretAlerts caused a non-recoverable error.
Please report this error to the mod author.

Error while running event GunTurretAlerts::on_tick (ID 0)
LuaItemStack API call when LuaItemStack was invalid.
stack traceback:
GunTurretAlerts/control.lua:27: in function <GunTurretAlerts/control.lua:5>
stack traceback:
[C]: in function 'index'
__GunTurretAlerts
/control.lua:27: in function <GunTurretAlerts/control.lua:5>

5 years ago

Since I don't have the other mod I can't really do my own testing. Try changing control.lua lines 24 through 28:

                    if inv_var.is_empty() then
                        ammo_left = 0
                    else
                        ammo_left = inv_var[1].count
                    end

into :
ammo_left = 0
ammo_dict = inv_var.get_contents()
for _, ammo_count in pairs(ammo_dict) do
ammo_left = ammo_left + ammo_count
end

If this works in your case I will include it in the next update.

New response