In train schedules, there are conditions "Time passed" and "Inactivity" selectable.
My question is: can I get these two values in control.lua? I want to know how much time the train has waited.
I tried finding related wording in LuaTrain, TrainSchedule, and even LuaEntity but have no luck yet.
Did I overlook something?
Any help is appreciated.
Can I get train time info from API?
-
- Fast Inserter
- Posts: 162
- Joined: Sun Oct 28, 2018 7:57 am
- Contact:
Re: Can I get train time info from API?
There are two more levels of nesting after TrainSchedule. TrainScheduleRecord and WaitCondition.
Code: Select all
train.schedule.records[1].wait_conditions[1].ticks
-
- Fast Inserter
- Posts: 162
- Joined: Sun Oct 28, 2018 7:57 am
- Contact:
Re: Can I get train time info from API?
Is it the actual time a train has already waited?DaveMcW wrote: ↑Sun Jun 14, 2020 7:18 pm There are two more levels of nesting after TrainSchedule. TrainScheduleRecord and WaitCondition.
Code: Select all
train.schedule.records[1].wait_conditions[1].ticks
Or is it the "theoretical" time set as condition in the schedule?
I want the value of the former one.
Re: Can I get train time info from API?
You would have to make a modding interface request if you want to read current progress.
You can calculate time passed by listening to on_train_changed_state to get tick 0, then subtracting it from the current tick.
You can calculate time passed by listening to on_train_changed_state to get tick 0, then subtracting it from the current tick.
-
- Fast Inserter
- Posts: 162
- Joined: Sun Oct 28, 2018 7:57 am
- Contact:
Re: Can I get train time info from API?
Somehow I have expected that... Just be sure not asking something already exist.
That's a brilliant idea! So a probably usable method even without an API request.You can calculate time passed by listening to on_train_changed_state to get tick 0, then subtracting it from the current tick.
I will now try implement it in my mod. Thank you for your suggestion!