How to know if locomotive is trying to accelerate in manual control?

Place to get help with not working mods / modding interface.
Post Reply
Rafiz
Inserter
Inserter
Posts: 31
Joined: Sun Jan 17, 2021 9:28 am
Contact:

How to know if locomotive is trying to accelerate in manual control?

Post by Rafiz »

I mean, there is "unreliable" method to check if train was moving and if it is moving now. But the problem is with for example 40 wagons this method won't work. It will think train is not trying to accelerate, because game will change train speed from 0 to 0.

How do I reliably know if train is trying to accelerate? I even thought of making key bindings to same as movement, but they are only sent once and there's no on_release event, so I wouldn't know when button is pressed anyway..

I also thought of method *is locomotive consuming fuel, compared to last frame* , but it won't give me information about direction of acceleration.

Perhaps if key was just pressed and in last frame fuel amount was bigger, then I can force train to start moving from halt, but it's very hacky way. I rely on 2 inputs to do one thing.

PFQNiet
Filter Inserter
Filter Inserter
Posts: 289
Joined: Sat Sep 05, 2020 7:48 pm
Contact:

Re: How to know if locomotive is trying to accelerate in manual control?

Post by PFQNiet »

Does player.riding_state.acceleration not give you this information?

Rafiz
Inserter
Inserter
Posts: 31
Joined: Sun Jan 17, 2021 9:28 am
Contact:

Re: How to know if locomotive is trying to accelerate in manual control?

Post by Rafiz »

Edit : I found this one : https://lua-api.factorio.com/latest/Lua ... ding_state it's even better.



Oh, it works very well!

so I can now know if automatic triain tries to accelerate with
(train.state == defines.train_state.on_the_path)

and I can know if player train tries to accelerate with
( ( train.state == defines.train_state.manual_control ) and (player.riding_state.acceleration==1) )



for anyone looking for info in this post
https://lua-api.factorio.com/latest/def ... celeration
https://lua-api.factorio.com/latest/def ... rain_state
together should give enough information.

Post Reply

Return to “Modding help”