Can I get train time info from API?

Place to get help with not working mods / modding interface.
Schallfalke
Fast Inserter
Fast Inserter
Posts: 162
Joined: Sun Oct 28, 2018 7:57 am
Contact:

Can I get train time info from API?

Post 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.
User avatar
DaveMcW
Smart Inserter
Smart Inserter
Posts: 3714
Joined: Tue May 13, 2014 11:06 am
Contact:

Re: Can I get train time info from API?

Post 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
Schallfalke
Fast Inserter
Fast Inserter
Posts: 162
Joined: Sun Oct 28, 2018 7:57 am
Contact:

Re: Can I get train time info from API?

Post 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.
User avatar
DaveMcW
Smart Inserter
Smart Inserter
Posts: 3714
Joined: Tue May 13, 2014 11:06 am
Contact:

Re: Can I get train time info from API?

Post 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.
Schallfalke
Fast Inserter
Fast Inserter
Posts: 162
Joined: Sun Oct 28, 2018 7:57 am
Contact:

Re: Can I get train time info from API?

Post 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-)
Post Reply

Return to “Modding help”