Will a function name in one script file overwrite the function in another one if they share the same name? Are scripts loaded into the global namespace or into a namespace that is specific to the mod, or are each scripts completely segregated?
I noticed that the scripts in the introductory scenario will call functions from another *.lua file without ever importing/requiring those other files so it appears all functions are global. Modded items themselves though always rely on there being a non local create() and update() pair of functions in their matching lua file which makes it look like those are not loaded globally since there are no clashes.
Do we need to make sure that all of our custom functions are defined as 'local' to prevent potential clashes?
Am I able to create any lua files that DONT have to be attached to a specific entity so that i can do global processing?
What is the scope enforcement on lua files in PA?
Moderator: NBJeff
Re: What is the scope enforcement on lua files in PA?
seronis wrote:Will a function name in one script file overwrite the function in another one if they share the same name? Are scripts loaded into the global namespace or into a namespace that is specific to the mod, or are each scripts completely segregated?
I noticed that the scripts in the introductory scenario will call functions from another *.lua file without ever importing/requiring those other files so it appears all functions are global. Modded items themselves though always rely on there being a non local create() and update() pair of functions in their matching lua file which makes it look like those are not loaded globally since there are no clashes.
Do we need to make sure that all of our custom functions are defined as 'local' to prevent potential clashes?
Am I able to create any lua files that DONT have to be attached to a specific entity so that i can do global processing?
I think each script file is entirely separate from all other files and also separate to each object instance. I also think importing other scripts is not enabled. I tried enabling import because I have a lot of common functions in my mods, but the import function was not available in the environment.
Re: What is the scope enforcement on lua files in PA?
At the moment, each scripted object has it's own lua state, which parses the lua script file of the scripted object. And nothing else. We've disabled a lot of the core libraries in order to avoid malicious mods being downloaded to people's systems. We're currently taking a very zealous approach. If the modding community want things in the mod system, we'd definitely consider them.
-
CoffeeBalls21
- level0
- Posts: 9
- Joined: Sun Feb 10, 2013 10:31 pm
- Location: United Kingdom
Re: What is the scope enforcement on lua files in PA?
I'm am interested in more catches like:
function Dump()
function Dismantle()
function Sell()
It would be a very nice way to do some clean up before the object and script associated with it was destroyed.
I am building a mod that has a multi object approach. When I build an object it also spawns in two other objects. but when I Dump or Dismantle this object the other spawned in objects remain. Is there currently a way to remove these objects as well on the removal of the main placed Object?
function Dump()
function Dismantle()
function Sell()
It would be a very nice way to do some clean up before the object and script associated with it was destroyed.
I am building a mod that has a multi object approach. When I build an object it also spawns in two other objects. but when I Dump or Dismantle this object the other spawned in objects remain. Is there currently a way to remove these objects as well on the removal of the main placed Object?
Re: What is the scope enforcement on lua files in PA?
CoffeeBalls21 wrote:I'm am interested in more catches like:
function Dump()
function Dismantle()
function Sell()
It would be a very nice way to do some clean up before the object and script associated with it was destroyed.
I am building a mod that has a multi object approach. When I build an object it also spawns in two other objects. but when I Dump or Dismantle this object the other spawned in objects remain. Is there currently a way to remove these objects as well on the removal of the main placed Object?
Make the other two scriptable. Let them check if your first object is around (GetNearbyObjects()). If not, delete them. Additionally you can save the Id of the first object as a variable and check for it if there will be many objects in a small place.
Good luck!
-
CoffeeBalls21
- level0
- Posts: 9
- Joined: Sun Feb 10, 2013 10:31 pm
- Location: United Kingdom
Re: What is the scope enforcement on lua files in PA?
Chad wrote:CoffeeBalls21 wrote:I'm am interested in more catches like:
Make the other two scriptable. Let them check if your first object is around (GetNearbyObjects()). If not, delete them. Additionally you can save the Id of the first object as a variable and check for it if there will be many objects in a small place.
Good luck!
Thanks, I know of this way buts its not very efficient. Doing GetNearbyObjects() uses a lot of power.
I will stick to this way for now, as i'm very excited to get my mod released. If there is more info on this in the modding API at a later time I will change it then.
Re: What is the scope enforcement on lua files in PA?
Object searches are expensive but that really only matters if you are doing them on a timer. Doing them once on object creation is a negligible cost unless your objects are being spawned continuously (many times a second)
Re: What is the scope enforcement on lua files in PA?
seronis wrote:Object searches are expensive but that really only matters if you are doing them on a timer. Doing them once on object creation is a negligible cost unless your objects are being spawned continuously (many times a second)
another problem is, if you spawn several 'connected' items on object creation. they have to check if their parent object ist still there continuously. there is no other way at the moment to check it.
Re: What is the scope enforcement on lua files in PA?
Agreed, i found it silly when I originally noticed we have constructors but not destructors for our scripted objects. Seems a bit of an oversight there.
Who is online
Users browsing this forum: No registered users and 5 guests




