S-S-X / metatool

Metatool API with few useful tools: Tube tool, Lua tool, Container tool, Magic pen, Sharetool, Digtron tool
MIT License
2 stars 1 forks source link

crash on travelnet use #26

Closed BuckarooBanzay closed 4 years ago

BuckarooBanzay commented 4 years ago

https://pandorabox.io/crashlogs/crash_2020-06-07_14-34.txt

2020-06-07 14:34:29: ERROR[Main]: ServerError: AsyncErr: ServerThread::run Lua: Runtime error from mod '' in callback item_OnUse(): /data/world//worldmods/metatool/sharetool/init.lua:112: attempt to index a nil value
2020-06-07 14:34:29: ERROR[Main]: stack traceback:
2020-06-07 14:34:29: ERROR[Main]:   /data/world//worldmods/metatool/sharetool/init.lua:112: in function 'set_travelnet_owner'
2020-06-07 14:34:29: ERROR[Main]:   .../world//worldmods/metatool/sharetool/nodes/travelnet.lua:55: in function 'paste'
2020-06-07 14:34:29: ERROR[Main]:   /data/world//worldmods/metatool/sharetool/init.lua:46: in function 'on_write_node'
2020-06-07 14:34:29: ERROR[Main]:   /data/world//worldmods/metatool/metatool/api.lua:257: in function </data/world//worldmods/metatool/metatool/api.lua:216>
OgelGames commented 4 years ago

Just need a nil check for this: https://github.com/S-S-X/metatool/blob/1b51d6d274e220a39a648f96716f171079d3a264/sharetool/init.lua#L112

I didn't have a network with the same name as the travelnet I used it on had.

if travelnet.targets[name] and travelnet.targets[name][network] then
    travelnet.targets[name][network][station] = nil
end
S-S-X commented 4 years ago

Should also check a bit better whole owner setting with travelnets as above does not really seem to work at least not always, mentioned other problems with removing travelnet from previous network here: https://github.com/S-S-X/metatool/issues/16#issuecomment-638252103

So it might be that it needs bit more tinkering than just that to make it all work correctly... I would have used functions provided by travelnet itself but it did not really offer usable functions for removing travelnet from one network.

I'll take a look at it and test a bit, that nil checking is still needed unless there's better way to remove station from network (through some function provided by travelnet mod).

S-S-X commented 4 years ago

Actually that whole thing was completely wrong and only seemed to work in some specific cases, it should have been travelnet.targets[current_owner][network][station] = nil instead of travelnet.targets[name][network][station] = nil and name should have been only used to send chat messages to player who used tool.

Also at beginning there's very inconsistent line local current_owner = meta:set_string('owner', owner) which should be local current_owner = meta:get_string('owner')

Maybe fixing these already fixes few other things too :facepalm:

S-S-X commented 4 years ago

Seems that above commit fixes it, also cleaned up code a bit and added location of duplicate travelnet station coords to error message.