Community Forum

Message passing between mods?

Forum Overview >> Scripting

CategoryScripting
Created13.06.2010 14:55


Christer F (Unknown) 13.06.2010 15:02
I'm woundering if any and so which ways is it possible to have some communication (message passing style) between mods (Vehicles)? Can such mods open network connections to send and listen on? Or can it be done by creating temporary files?
Both ways are ugly, isn't there any more direct way?
I'm new to Lua and as I know that the mods are loaded in separate namespaces so I don't know if it is possible to create any direct "connection" between them.

Thanks in advance!


Tobias F (JD6930) 13.06.2010 22:48
what kind of connection do you mean ?

Christer F (Unknown) 15.06.2010 01:43
Sending messages as Lua tables I guess would be the best. The scripts should be built to agree on one common structure for this message table that is sent.

Example usage:
I make a small square baler with a bale thrower. A special made bale wagon attached behind the baler could "tell" the baler (the thrower) where it want a bale to land when it's about to be thrown.
This way the mods could automatically compensate for when the whole equipage is turning, when the angle between the baler and the wagon isn't the same as when driving straight and bale would fall at the sides of the wagon.

It could be even more advanced if the wagon also requests how far the bale should be thrown so it always know precisely where the bale is going to land. Add a lite bit of random rotation and the bales will create a non-organized stack as in reality. When the baler takes a bale it makes it non-rigid (avoid simulating physics) but it would look like the bales where randomly dropped into the wagon.

Stefan Geiger - GIANTS Software 16.06.2010 16:37
Since all code is running on the same computer you can directly call functions of classes of other mods. You don't have to introduce some complex message passing system.

The only thing you need to do, is to get somehow the instance of the class of the other mod. In your example, this is quite easy, since you always know who you are attached to.


So your special bale wagon would have a function
onAttach(attacherVehicle)

and do something like this:
if (attacherVehicle.myModBaler ~= nil and attacherVehicle.myModBaler == 192) then
--do some special stuff afterwards with the bales
--you can call also attacherVehicle:someSpecialFunctionWhichIsAvailableInYourMod
end;

Your baler should have an attribute myModBaler = 192. In this way the bale wagon can detect if the attacher vehicle really is a baler you are expecting

Christer F (Unknown) 17.06.2010 00:10
Thanks! This is great, now I can do some cool functionality :)


Note: Log in to post. Create a new account here.