Lua question re script 2 script communication

Started by garry23, November 14, 2016, 06:02:15 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

garry23

David

If you are able to give me a pointer regarding this question that would be great.

Say I have two scripts, A and B.

Can I call a function in A from within B?

If so, how  ;)

Cheers

Garry

dmilligan

No, not directly. Can you describe more precisely what you are trying to do? and what is your goal? Reuse some common code? Or a communication channel?

garry23

David

Script A does certain things, as does s riot B.

Script A runs directly from pressing keys, i.e. you don't go through the ML menu. Script B only operates through the ML menu.

I could combine A and B into a new script C, with combined functionality, and this is what I might do.

The alternative I thought was to extend the functionality of A by running some of the functions in B, from A.

But from what I know and what you are implying, I think I just write a single mother of all scripts, i.e. A combined script C. Or lift the functions from A into C.

Cheers

Garry

dmilligan

If you just want to reuse some common code, you can put that code in a script in the lib folder and load it like a library with require(). If the two scripts need to share state, then you probably ought to combine them.