aboutsummaryrefslogtreecommitdiff
path: root/advtrains/trainlogic.lua
diff options
context:
space:
mode:
authororwell96 <orwell@bleipb.de>2019-01-21 22:26:11 +0100
committerorwell96 <orwell@bleipb.de>2019-01-21 22:26:11 +0100
commite915b61da6f18efa49b6afacb7e9ca181d59cc5c (patch)
tree6c0038a03bf70842ae27ed5c6eb89c42eece9818 /advtrains/trainlogic.lua
parent97145e0f062f34f6d4803c57f867253dc0e02342 (diff)
downloadadvtrains-e915b61da6f18efa49b6afacb7e9ca181d59cc5c.tar.gz
advtrains-e915b61da6f18efa49b6afacb7e9ca181d59cc5c.tar.bz2
advtrains-e915b61da6f18efa49b6afacb7e9ca181d59cc5c.zip
Index NaN check (tracking obscure error detected on LW migration)
Diffstat (limited to 'advtrains/trainlogic.lua')
-rw-r--r--advtrains/trainlogic.lua10
1 files changed, 9 insertions, 1 deletions
diff --git a/advtrains/trainlogic.lua b/advtrains/trainlogic.lua
index bf17133..1406080 100644
--- a/advtrains/trainlogic.lua
+++ b/advtrains/trainlogic.lua
@@ -454,8 +454,16 @@ function advtrains.train_step_b(id, train, dtime)
end
--- 4. move train ---
-
+ local oi = train.index
train.index=train.index and train.index+((train.velocity/(train.path_dist[math.floor(train.index)] or 1))*dtime) or 0
+ if train.index ~= train.index then -- This is a check whether index is "NaN" https://stackoverflow.com/questions/37753694/lua-check-if-a-number-value-is-nan
+ atwarn("Index of train is NaN!")
+ advtrains.path_print(train, atwarn)
+ atwarn("Calculation index=",oi,"+(",train.velocity,"/",train.path_dist[math.floor(train.index)],"*",dtime)
+ advtrains.path_invalidate(train)
+ train.wait_for_path = true
+ return
+ end
recalc_end_index(train)
end