aboutsummaryrefslogtreecommitdiff
path: root/advtrains/couple.lua
diff options
context:
space:
mode:
authororwell96 <orwell@bleipb.de>2018-10-29 21:19:49 +0100
committerorwell96 <orwell@bleipb.de>2018-10-29 21:19:49 +0100
commit93726db4e3c36878981b5eb934b3599a50bc6619 (patch)
treecc0a5d5db9589bcd026b671f6d1f7f81b218aa02 /advtrains/couple.lua
parent6298f8b081fd0fa05552f2b658281b0e6e950d38 (diff)
downloadadvtrains-93726db4e3c36878981b5eb934b3599a50bc6619.tar.gz
advtrains-93726db4e3c36878981b5eb934b3599a50bc6619.tar.bz2
advtrains-93726db4e3c36878981b5eb934b3599a50bc6619.zip
Handle the case that a train is not initialized (train_ensure_init returns nil/false)
Fixes H#72
Diffstat (limited to 'advtrains/couple.lua')
-rw-r--r--advtrains/couple.lua21
1 files changed, 17 insertions, 4 deletions
diff --git a/advtrains/couple.lua b/advtrains/couple.lua
index 1aac0b3..a77731e 100644
--- a/advtrains/couple.lua
+++ b/advtrains/couple.lua
@@ -98,8 +98,14 @@ minetest.register_entity("advtrains:couple", {
local train1=advtrains.trains[self.train_id_1]
local train2=advtrains.trains[self.train_id_2]
- advtrains.train_ensure_init(self.train_id_1, train1)
- advtrains.train_ensure_init(self.train_id_2, train2)
+ if not advtrains.train_ensure_init(self.train_id_1, train1) then
+ atwarn("Train",self.train_id_1,"is not initialized! Operation aborted!")
+ return
+ end
+ if not advtrains.train_ensure_init(self.train_id_2, train2) then
+ atwarn("Train",self.train_id_2,"is not initialized! Operation aborted!")
+ return
+ end
local id1, id2=self.train_id_1, self.train_id_2
local bp1, bp2 = self.t1_is_front, self.t2_is_front
@@ -160,8 +166,15 @@ minetest.register_entity("advtrains:couple", {
return
end
- advtrains.train_ensure_init(self.train_id_1, train1)
- advtrains.train_ensure_init(self.train_id_2, train2)
+ --shh, silence here, this is an on-step callback!
+ if not advtrains.train_ensure_init(self.train_id_1, train1) then
+ --atwarn("Train",self.train_id_1,"is not initialized! Operation aborted!")
+ return
+ end
+ if not advtrains.train_ensure_init(self.train_id_2, train2) then
+ --atwarn("Train",self.train_id_2,"is not initialized! Operation aborted!")
+ return
+ end
if train1.velocity>0 or train2.velocity>0 then
if not self.position_set then --ensures that train stands a single time before check fires. Using flag below