Notifications
Clear all

To all SSC Station occupants

Thank you for the donations over the past year (2024), it is much appreciated. I am still trying to figure out how to migrate the forums to another community software (probably phpbb) but in the meantime I have updated the forum software to the latest version. SSC has been around a while so their is some very long time members here still using the site, thanks for making SSC home and sorry I haven't been as vocal as I should be in the forums I will try to improve my posting frequency.

Thank you again to all of the members that do take the time to donate a little, it helps keep this station functioning on the outer reaches of space.

-D1-

LUA modding question

(@jackwild)
New Member

Hi, great game, good progress etc..

 

So I've been playing with the LUA scripting and looking at the core scripts and other contributions on the wiki. I can't seem to find any examples of splitting a script into discreet modules. Is there an official way of doing this or do all scripts have to be contained in one text file? I'd like to be able to call functions from a seperate module so that I can split the logic of what I'm playing with at the moment. I don't know much about LUA but from what I've read in other modding communities it seems that loading order is usually they key. Is it as simple as naming the files so they load in a predictable order? How do I access an outside namespace? Should I declare global functions (I can't imagine that's a good idea for fear of clashing mods in the future)? Has any thought been given to this?

 

Sorry for the noobishness

Quote
Topic starter Posted : March 31, 2013 08:06
(@fluffyfreak)
Noble Member

I don't know about this and the people who'd normally answer are currently otherwise engaged.

 

So for now it seems as though you'll have to do it all in a single large file I think :/

 

Sorry for not being much more use.

 

Andy

 

EDIT: Brianetta would be the best person to ask, but I think he's lost in Minecraft server somewhere recently 😀 He might be receptive to a polite PM (message).

ReplyQuote
Posted : April 2, 2013 13:31
 robn
(@robn)
Noble Member

Right now we don't really have a lot of structure or abstraction in Lua files. We've recognised for a while that its needed, but nobody has quite got around to it yet.

For the moment dependencies are managed via load order, which is just done in filename sort order. We put numbered prefixes on filenames that we want to load early. We have done some work towards a proper dependency declaration thing, where each script explicitly names the things it wants to use, but that's not there. Sometime later we want to be able to sandbox individual scripts.

If you can, avoid creating globals, except for things that are truly global (typically library tables). Something we've thought about is actually sandboxing individual modules, which among other things would give each module its own global table. But even without that, you want avoid clashes as much as possible.

Sorry that's a bit vague. As I said, its an area we know needs work, it just hasn't happened yet.

ReplyQuote
Posted : April 2, 2013 15:29
(@brianetta)
Prominent Member

EDIT: Brianetta would be the best person to ask, but I think he's lost in Minecraft server somewhere recently 😀 He might be receptive to a polite PM (message).

Rob gave a fairly complete answer, although there's nothing to prevent script authors from writing scripts in several files and using the Event library to have functions in the different local file scopes communicate with each other.

I'm not the only one lost in a Minecraft server. My wife is also lost in the same Minecraft server. It's quite the bonding experience.

ReplyQuote
Posted : April 3, 2013 04:29
(@jackwild)
New Member

Thanks.

 

It's an interesting idea Brianetta but i wonder if you could expand on using the Event library for inter-script communication. It looks to me like you could Queue an Event in one script and respond in another something like:

 

 


Event.Queue(name, args)

 

and then in another script  




func(args)
  do awesome things
end
Event.Register(name, func)
 

Is this the right idea and is it restricted to hard-coded events and their expected arguments? Or is it that you mean just split the event response functions across multiple files with no communication?

ReplyQuote
Topic starter Posted : April 3, 2013 07:18
(@brianetta)
Prominent Member

That's exactly the idea. It's not restricted to hard-coded events. Event is a globally namespaced class, so you can have events queued from one script to be handled by a function in another.

ReplyQuote
Posted : April 4, 2013 04:37