LJD Vehicles (continued)


Adds a large hauling truck with customisable inventory size

Content
4 months ago
2.0
888
Transportation Storage

g AAI Programmble Vehicles integration

4 months ago
(updated 4 months ago)

Currently, this hauling truck would be perfect for the AAI Programmble Vehicles mod, but it has one problem - its not being detected as a "hauling" vehicle.

If you were to create a "control.lua" file in the root of the mod with these contents:

remote.add_interface("LJD_Vehicles_Continued", { hauler_types = function(data) return {'hauling-truck'} end})

Then this truck will properly get detected as a hauler.

4 months ago

Sure, I can do that. I dislike just pasting code I don't understand, though, give me a bit to dig through the Lua API and figure out what you're actually asking me to do :) Specifically, how remote.add_interface works, and what exactly AAI Vehicles is expecting.

Wouldn't be opposed to an explanation if you have one, either.

4 months ago

Had a chance to look through AAI Vehicles. Looks like it's checking for a "hauler types" interface and adding everything from there to its own remote table. Not sure what it does with that data, and it really doesn't matter. I added the remote interface to LJD Vehicles as instructed.

AAI Vehicles is a very complex mod that I know nothing about, so I haven't been able to test the change. Vehicle still functions as normal, is all I can say. Let me know if it works.

4 months ago
(updated 4 months ago)

remote.add_interface("LJD_Vehicles_Continued", { hauler_types = function(data) return {'hauling-truck'} end}) will add a new interface with the name "LJD_Vehicles_Continued". This interface contains an array of remote functions provided by your mod. I suppose AAI will check all remote interfaces active in the game and call the function hauler_types if it is available. The function is expected to return an array with the names of car prototypes provided by your mod that AAI should consider.

I suppose AAI will call these remote functions in script.on_init and script.on_configuration_changed to update its database of the vehicle prototypes it must handle.

4 months ago

Yeah, I dug through AAI Vehicle's runtime scripts. It literally walks the list of active mods and calls hauler_types on all of them, then walks the list of vehicles returned to add them into its own "remote" data structures. What was throwing me originally was the use of the term "interface". My background is in OOP, so I'm used to an "Interface" being a reference type. In Factorio, it seems to rather be just a table of functions available to all active mods - so "interface" in the colloquial sense.

Still haven't tested the change, though. So please let me know if it actually works, if possible :)

4 months ago

I'm haven't really played with AAI Programmable Vehicles yet either (my interest in the truck and AAI Programmable Vehicles is compatibility with my mod Autodrive, which I haven't updated yet for Factorio 2.0). But using Lua API global Variable Viewer (gvv), I noticed that AAI's storage.hauler_types now contains your vehicle, so I suppose the change did work. :-)

4 months ago

Neat! Thanks for the heads-up :) Let me know if you need any further changes for compatibility. I'm just happy to bring an old mod back to life.

New response