You can check my haulgoods.lua script in http://www.avorion.net/forum/index.php/topic,2896.0.html
It calls functions in the same script in other objects and has some simple things in there to check/test/set/return values in other objects.
Basically you make functions in the object that set or return the values in that object.
Example to set or get the debuglevel in an object that's running my script:
function getDebugLevel() return debugLevel end
function setDebugLevel(arg) debugLevel = tonumber(arg) end
Which will set the global debugLevel in the script this function is called in.
Called like this:
local retval, level = ship:invokeFunction(haulscript, "getDebugLevel")
local retval = ship:invokeFunction(haulscript, "setDebugLevel", debugLevel)
You need to let go of the C++ type OOP implementations, where "object" is just the name of a blob of code, and start thinking as objects being *actual* objects, like a ship, or a station, or a sector.
To find all ships in a sector, you will call a function in the sector that will return a list of ship objects. Each of these ship objects have a number of scripts attached to them that will have certain functionality. In my example, "haulscript" is the global variable I've defined that contains the definition of the script that provides the setDebugLevel and getDebugLevel functions for JUST that script.
local haulscript = "data/scripts/entity/ai/haulgoods.lua"
Another script can have exactly the same functions, but will still only work in the context of that script attached to that specific ship object.
Within the script, Entity() will be the object it's attached to.
There is a lot of function documentation (very unfinished) in the Documentation folder of your Avorion install.
Thank you for response and tips. I actually already figured out and implemented some variables system that syncs them when I need it. And my mod is almost ready for the beta-release, I think.
Now I just trying to figure out how to uninstall mods properly.
I get this in my logs after reverting to the vanilla scripts: "Loading of sector (x:y) failed. Treating sector as non-exsting. Error: Script 'data/scripts/entity/myScript.lua' not found. Tried the following paths:".
So, as I understand, server saves object with my script attached to them. So right now I'm looking in the mods of other people to understand how they deal with this.
UPD: As I see, there is no good ways to uninstall mod that attaches scripts right now. Basically everyone just replaces attached scripts content with "terminate()" and tells users that they need to delete this files when they're 100% sure, that scripts are unattached