Author Topic: Lua question re script 2 script communication  (Read 1627 times)

garry23

  • Contributor
  • Hero Member
  • *****
  • Posts: 1717
Lua question re script 2 script communication
« on: November 14, 2016, 06:02:15 PM »
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

  • Developer
  • Hero Member
  • *****
  • Posts: 3217
  • 60Da / 1100D / EOSM
Re: Lua question re script 2 script communication
« Reply #1 on: November 15, 2016, 04:01:14 AM »
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

  • Contributor
  • Hero Member
  • *****
  • Posts: 1717
Re: Lua question re script 2 script communication
« Reply #2 on: November 15, 2016, 07:31:46 AM »
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

  • Developer
  • Hero Member
  • *****
  • Posts: 3217
  • 60Da / 1100D / EOSM
Re: Lua question re script 2 script communication
« Reply #3 on: November 15, 2016, 01:00:45 PM »
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.