Page 1 of 1
Controlling trains by script using dummy?
Posted: Tue Feb 07, 2017 12:04 am
by Melfish
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?
Re: Controlling trains by script using dummy?
Posted: Tue Feb 07, 2017 2:18 am
by Sirenfal
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
Re: Controlling trains by script using dummy?
Posted: Tue Feb 07, 2017 6:54 am
by Adil
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.
Re: Controlling trains by script using dummy?
Posted: Tue Feb 07, 2017 3:19 pm
by Melfish
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.
Re: Controlling trains by script using dummy?
Posted: Tue Feb 07, 2017 7:27 pm
by Adil
Melfish 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.
Oww. I guess it means that it can only be used on cars and players then
. I've never tried to control trains.
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
Maybe this will even work.
Re: Controlling trains by script using dummy?
Posted: Tue Feb 07, 2017 8:32 pm
by Nexela
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