diff options
author | orwell96 <mono96.mml@gmail.com> | 2017-01-17 15:29:37 +0100 |
---|---|---|
committer | orwell96 <mono96.mml@gmail.com> | 2017-01-17 15:29:37 +0100 |
commit | 275579c36425601078716f7f26bb3ac3e5b2ca99 (patch) | |
tree | a96b8447302a1d4acb480d2ce1c22bf6fe002e01 | |
parent | b649ea5fe4c9a7bc9b2b318fec97e5abe470fa9b (diff) | |
download | advtrains-275579c36425601078716f7f26bb3ac3e5b2ca99.tar.gz advtrains-275579c36425601078716f7f26bb3ac3e5b2ca99.tar.bz2 advtrains-275579c36425601078716f7f26bb3ac3e5b2ca99.zip |
Don't crash when wagons do not exist but show a warning instead
-rw-r--r-- | advtrains/advtrains/atc.lua | 4 | ||||
-rw-r--r-- | advtrains/advtrains/trainlogic.lua | 8 |
2 files changed, 8 insertions, 4 deletions
diff --git a/advtrains/advtrains/atc.lua b/advtrains/advtrains/atc.lua index ece7075..2a4d226 100644 --- a/advtrains/advtrains/atc.lua +++ b/advtrains/advtrains/atc.lua @@ -23,11 +23,11 @@ end function atc.send_command(pos) local pts=minetest.pos_to_string(pos) if atc.controllers[pts] then - atprint("Called send_command at "..pts) + --atprint("Called send_command at "..pts) local train_id = advtrains.detector.on_node[pts] if train_id then if advtrains.trains[train_id] then - atprint("send_command inside if: "..sid(train_id)) + --atprint("send_command inside if: "..sid(train_id)) atc.train_reset_command(train_id) local arrowconn=atc.controllers[pts].arrowconn local train=advtrains.trains[train_id] diff --git a/advtrains/advtrains/trainlogic.lua b/advtrains/advtrains/trainlogic.lua index c9c7403..5bedfec 100644 --- a/advtrains/advtrains/trainlogic.lua +++ b/advtrains/advtrains/trainlogic.lua @@ -474,7 +474,7 @@ function advtrains.update_trainpart_properties(train_id, invert_flipstate) for i, w_id in ipairs(train.trainparts) do local wagon=nil for aoid,iwagon in pairs(minetest.luaentities) do - if iwagon.is_wagon and iwagon.initialized and iwagon.unique_id==w_id then + if iwagon.is_wagon and iwagon.unique_id==w_id then if wagon then --duplicate atprint("update_trainpart_properties: Removing duplicate wagon with id="..aoid) @@ -488,7 +488,11 @@ function advtrains.update_trainpart_properties(train_id, invert_flipstate) if advtrains.wagon_save[w_id] then --spawn a new and initialize it with the properties from wagon_save wagon=minetest.env:add_entity(train.last_pos, advtrains.wagon_save[w_id].entity_name):get_luaentity() - wagon:init_from_wagon_save(w_id) + if not wagon then + minetest.chat_send_all("[advtrains] Warning: Wagon "..advtrains.wagon_save[w_id].entity_name.." does not exist. Make sure all required modules are loaded!") + else + wagon:init_from_wagon_save(w_id) + end end end if wagon then |