Hey guys, I am currently in the process of making a mod in which I need to control trains by script instead of a schedule.
The API does mention it is possible to control a train by script, and using the player I can use its riding_state to make it work. (Even though it is marked as read-only, but I could not find any other way and tried it anyway.)
To not have to use the player, I have to use some kind of in-game dummy player, but is this even possible?
Controlling trains by script using dummy?
Re: Controlling trains by script using dummy?
Use the LuaTrain object, not the entity. This can be accessed by the train property on any of the entities composing the train (cargo wagons or locomotives).
http://lua-api.factorio.com/latest/LuaE ... tity.train
http://lua-api.factorio.com/latest/LuaTrain.html
http://lua-api.factorio.com/latest/LuaE ... tity.train
http://lua-api.factorio.com/latest/LuaTrain.html
Re: Controlling trains by script using dummy?
You don't have to use dummy characters, `riding_state` is available in the vehicle itself.
And yes, it is possible to define a dummy entity of type "character" to use for your own needs.
And yes, it is possible to define a dummy entity of type "character" to use for your own needs.
I do mods. Modding wiki is friend, it teaches how to mod. Api docs is friend too...
I also update mods, some of them even work.
Recently I did a mod tutorial.
I also update mods, some of them even work.
Recently I did a mod tutorial.
Re: Controlling trains by script using dummy?
The LuaTrain does not seem to have the riding_state, as I get an error that it does not contain the key... (adding it doesn't work)
I have also tried to use it on the train entity (just to try everything) , nothing happens. Trying to read the state gives an error that it can only be used on player and car entities.
I have also tried to use it on the train entity (just to try everything) , nothing happens. Trying to read the state gives an error that it can only be used on player and car entities.
Re: Controlling trains by script using dummy?
Oww. I guess it means that it can only be used on cars and players thenMelfish wrote:The LuaTrain does not seem to have the riding_state, as I get an error that it does not contain the key... (adding it doesn't work)
I have also tried to use it on the train entity (just to try everything) , nothing happens. Trying to read the state gives an error that it can only be used on player and car entities.

However, "player" is actually a type of entities that usually represents player's character. (And there also happens to be an entity of type "player" named "player")
So you could try to do something like:
Code: Select all
driver = locomotive.surface.nauvis.create_entity{name='player',position={0,0},force=locomotive.force}
locomotive.passenger=driver
driver.riding_state=...---and so on
I do mods. Modding wiki is friend, it teaches how to mod. Api docs is friend too...
I also update mods, some of them even work.
Recently I did a mod tutorial.
I also update mods, some of them even work.
Recently I did a mod tutorial.
Re: Controlling trains by script using dummy?
You can take a peek at the current version of the FARL mod to see how this is handled. My guess is very similar to the Adil's example