Train Toggle

by henkoe

Press J (default) to toggle trains between automatic and manual mode when inside a train

Content
6 years ago
0.16
10
Trains

b Crash when outside of train

6 years ago
(updated 6 years ago)

The script crashes on line 7 in control.lua because the condition vehicle and vehicle.type == "locomotive" or "cargo-wagon" or "fluid-wagon" is malformed.
You can't use or in a comparison like that.

I would suggest doing something like vehicle and ({['locomotive']=true, ['cargo-wagon']=true, ['fluid-wagon']=true})[vehicle.type]. Ideally you would even move the table into a local outside the event so it doesn't need to be created over and over again.

EDIT: Just realized I didn't really say what the error is - it is __TrainToggle__/control.lua:7: attempt to index local 'vehicle' (a nil value).

Cheers TRK

New response