Notifications
Clear all

 


I use crypto.com app personally on a daily basis and its great and takes the stress out of learning crypto and the crypto debit cards are great, ask me anything on this. I will probably make a thread discussing crypto soon. REFERRAL CODE = p5mu64hcq4
 

LUA modding question


jackwild
(@jackwild)
Crewman Registered
Joined: 10 years ago
Posts: 2
Topic starter  

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
fluffyfreak
(@fluffyfreak)
Captain Registered
Joined: 6 years ago
Posts: 1306
 

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
robn
 robn
(@robn)
Captain Registered
Joined: 12 years ago
Posts: 1035
 

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
Brianetta
(@brianetta)
Commander Registered
Joined: 12 years ago
Posts: 863
 

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
jackwild
(@jackwild)
Crewman Registered
Joined: 10 years ago
Posts: 2
Topic starter  

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
Brianetta
(@brianetta)
Commander Registered
Joined: 12 years ago
Posts: 863
 

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