Page 1 of 1

Can I get train time info from API?

Posted: Sun Jun 14, 2020 7:15 pm
by Schallfalke
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.

Re: Can I get train time info from API?

Posted: Sun Jun 14, 2020 7:18 pm
by DaveMcW
There are two more levels of nesting after TrainSchedule. TrainScheduleRecord and WaitCondition.

Code: Select all

train.schedule.records[1].wait_conditions[1].ticks

Re: Can I get train time info from API?

Posted: Sun Jun 14, 2020 8:14 pm
by Schallfalke
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
Is it the actual time a train has already waited?
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?

Posted: Sun Jun 14, 2020 8:35 pm
by DaveMcW
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.

Re: Can I get train time info from API?

Posted: Sun Jun 14, 2020 8:50 pm
by Schallfalke
DaveMcW wrote: Sun Jun 14, 2020 8:35 pm You would have to make a modding interface request if you want to read current progress.
Somehow I have expected that... Just be sure not asking something already exist.
You can calculate time passed by listening to on_train_changed_state to get tick 0, then subtracting it from the current tick.
That's a brilliant idea! So a probably usable method even without an API request.
I will now try implement it in my mod. Thank you for your suggestion! 8-)