Page 1 of 1
Where is the file with the behaviour for the train waiting conditions defined?
Posted: Sat Jul 16, 2022 8:42 am
by Johannes_00
Hello, i want to make a little mod which adds waiting conditions for the trains.
However, i just can't find the file that defines for which type of waiting condition it does what.
Shouldn't there be a file like control.lua which defines the behaviour for the trains and other entities?
Re: Where is the file with the behaviour for the train waiting conditions defined?
Posted: Sat Jul 16, 2022 11:12 am
by robot256
99.9% of the Factorio application is written in C++ and compiled into a binary executable before distribution. The only reason mods can execute Lua code is because the C++ source includes a sandboxed Lua interpreter and API functions that allow Lua to trigger certain changes in the C++ game state. This is the reason, for example, that a crash in Lua code does not crash Factorio to the desktop: the Lua code is a "guest" training on top of the C++ application.
Train scheduling and pathfinding is all executed directly within the C++ game. The API allows mods to alter train schedules at any time using the available schedule record and condition types. More complex behavior can be achieved by having the mod modify a train's schedule at specific times, based on other information the mod collects. A few schedule record types are available to mods which the player cannot access: Temporary station records and permanent rail-coordinate records.
Re: Where is the file with the behaviour for the train waiting conditions defined?
Posted: Sat Jul 16, 2022 12:17 pm
by robot256
Johannes_00 wrote: Sat Jul 16, 2022 8:42 am
Hello, i want to make a little mod which adds waiting conditions for the trains.
However, i just can't find the file that defines for which type of waiting condition it does what.
Shouldn't there be a file like control.lua which defines the behaviour for the trains and other entities?
I might have misread your question. To expand on my previous answer, to find what API features are available for mod Lua code to use, look in the Lua API documentation:
https://lua-api.factorio.com/latest/index.html
The schedule of a Train can be read or written using
LuaTrain::schedule. To write the schedule, you must create the full schedule as a Lua Table according to the
TrainSchedule format, which includes an array of
TrainScheduleRecord tables, which each include an array of
WaitCondition tables, which can each be set to one of the listed types.
Re: Where is the file with the behaviour for the train waiting conditions defined?
Posted: Sat Jul 16, 2022 2:53 pm
by FuryoftheStars
robot256 wrote: Sat Jul 16, 2022 12:17 pm
Johannes_00 wrote: Sat Jul 16, 2022 8:42 am
Hello, i want to make a little mod which adds waiting conditions for the trains.
However, i just can't find the file that defines for which type of waiting condition it does what.
Shouldn't there be a file like control.lua which defines the behaviour for the trains and other entities?
I might have misread your question.
I was reading it the same way you initially did. It sounds like they want to create new wait conditions and define their behavior, which, of course, can’t be done as that’s all engine side.
Re: Where is the file with the behaviour for the train waiting conditions defined?
Posted: Sat Jul 16, 2022 3:30 pm
by Johannes_00
robot256 wrote: Sat Jul 16, 2022 12:17 pm
Johannes_00 wrote: Sat Jul 16, 2022 8:42 am
Hello, i want to make a little mod which adds waiting conditions for the trains.
However, i just can't find the file that defines for which type of waiting condition it does what.
Shouldn't there be a file like control.lua which defines the behaviour for the trains and other entities?
I might have misread your question. To expand on my previous answer, to find what API features are available for mod Lua code to use, look in the Lua API documentation:
https://lua-api.factorio.com/latest/index.html
The schedule of a Train can be read or written using
LuaTrain::schedule. To write the schedule, you must create the full schedule as a Lua Table according to the
TrainSchedule format, which includes an array of
TrainScheduleRecord tables, which each include an array of
WaitCondition tables, which can each be set to one of the listed types.
You actually didn't misread the question. My intention was, as FuryoftheStars said, to add new types of waiting conditions like "full_cargo_wagons" and then extend this new case with the appropriate behaviour where its initially defined.
Re: Where is the file with the behaviour for the train waiting conditions defined?
Posted: Sat Jul 16, 2022 3:58 pm
by robot256
Johannes_00 wrote: Sat Jul 16, 2022 3:30 pm
You actually didn't misread the question. My intention was, as FuryoftheStars said, to add new types of waiting conditions like "full_cargo_wagons" and then extend this new case with the appropriate behaviour where its initially defined.
I have used the Inventory Sensor mod in the past to read the contents of each individual wagon, calculate what I need, and send it to a circuit schedule condition.