Inter-instrument communication

Help creating logic scripts for Air Manager Instruments

Moderators: russ, Ralph

Message
Author
User avatar
Sling
Posts: 5237
Joined: Mon Sep 11, 2017 2:37 pm
Contact:

Re: Inter-instrument communication

#51 Post by Sling »

Tetrachromat wrote: Fri Nov 05, 2021 11:28 am @Detlef In your server instrument the request_callback references the variable 'cbAircraftDescription'. But there is no variable in scope with that name. That vraiable is defined in the user instrument.

Although as global variable, but it is not shared between instruments.

Each instrument has it's own environment. They do not share anything else than the lua libraries and API.

Paul
cbAircraftDescription Is not a variable as such in this case but a function name. But yes if it’s there because he is thinking it will force the callback in another instrument to fire, then it is incorrect as you mention. The posted code is not complete so it’s anyone’s guess as to what other code is in each of the instruments.

I’ve lost track of what the intended purpose of this is now but whatever it is this seems over complex. KISS principals.

Tetrachromat
Posts: 236
Joined: Sun Feb 14, 2021 6:55 pm

Re: Inter-instrument communication

#52 Post by Tetrachromat »

Sling wrote: Fri Nov 05, 2021 12:59 pm cbAircraftDescription Is not a variable as such in this case but a function name.
Lua treats that 'cbAircraftDescription' as a global variable and it will evaluate to nil before calling the API function. Insert the statement

Code: Select all

  log(cbAircraftDescription) 

before the request. It will be logged as 'nil'.

There are no named functions in Lua, like in other programming languages. Functions in Lua are data types like strings or numbers. Only when you assign a function to a variable you can call it by the name of the variable. Otherwise they are anonymous.

Code: Select all

function cbAircraftDescription(name_array)
	<body
end
is just syntactic sugar for

Code: Select all

cbAircraftDescription = function (name_array) <body> end
This is functional programming. One needs to get accustomed to that style.

Paul

Tetrachromat
Posts: 236
Joined: Sun Feb 14, 2021 6:55 pm

Re: Inter-instrument communication

#53 Post by Tetrachromat »

Ralph wrote: Fri Nov 05, 2021 12:39 pm With Lua libraries I hope you do not mean the libraries within the instrument folder :)
Ah no, I was referring to the lua_libs folder in the installation directory.

User avatar
Keith Baxter
Posts: 4685
Joined: Wed Dec 20, 2017 11:00 am
Location: Botswana

Re: Inter-instrument communication

#54 Post by Keith Baxter »

Hi,

Yes the var needs to be declared before any read or write.

I assume that AM uses a double pass on initiation?

Keith
AMD RYZEN 9 5950X CPU, Corsair H80I cooler, ASUS TUF GAMING B550-PLUS AMD Ryzen Mother Board,  32Gb ram Corsair Vengeance 3000Mh, MSI GTX960 4G graphics card 

Tetrachromat
Posts: 236
Joined: Sun Feb 14, 2021 6:55 pm

Re: Inter-instrument communication

#55 Post by Tetrachromat »

@Detlef I think the issue with your user instruments not reporting is because the user instruments are reporting only when they receive notice of the command sent.

If the user instrument is loaded after the master, it will miss the command sent by the master. I think commands ar not persisted in the plugin. so the user instruments do not receive a command sent before subscribing.

My design for such a scenario would be to leave the responsibility to report the instrument state completely with the user instrument. All user instruments should report their state on startup, without being asked by the master. As the reporting is through a si_variable, the states will be persisted in the plugin. The master will receive the states whether it is up before or after the user instruments.

You should never assume a certain startup sequence. The startup sequene is not predictable, it could be different each time you start the panel.

If you need assistance for a redesign, feel free to ask.

Paul

User avatar
Ralph
Posts: 7923
Joined: Tue Oct 27, 2015 7:02 pm
Location: De Steeg
Contact:

Re: Inter-instrument communication

#56 Post by Ralph »

That's correct, a command is 'fire and forget'.

User avatar
Sling
Posts: 5237
Joined: Mon Sep 11, 2017 2:37 pm
Contact:

Re: Inter-instrument communication

#57 Post by Sling »

Tetrachromat wrote: Fri Nov 05, 2021 1:16 pm
Sling wrote: Fri Nov 05, 2021 12:59 pm cbAircraftDescription Is not a variable as such in this case but a function name.
Lua treats that 'cbAircraftDescription' as a global variable and it will evaluate to nil before calling the API function. Insert the statement

Code: Select all

  log(cbAircraftDescription)

before the request. It will be logged as 'nil'.

There are no named functions in Lua, like in other programming languages. Functions in Lua are data types like strings or numbers. Only when you assign a function to a variable you can call it by the name of the variable. Otherwise they are anonymous.

Code: Select all

function cbAircraftDescription(name_array)
	<body
end
is just syntactic sugar for

Code: Select all

cbAircraftDescription = function (name_array) <body> end
This is functional programming. One needs to get accustomed to that style.

Paul
I know all of that and don’t need a Lua lesson. You’ll notice I said not a variable as such because using that term when helping beginners and in the context of this discussion I find adds confusion. For the basics of AM learning it is a function with a name and the request_callback() function expects you to supply the name of a function. It helps to refer to it as such. You have to remember the vast majority of folks that write scripts for AM need things kept simple.

We are off topic so best to get back on topic.

User avatar
Ralph
Posts: 7923
Joined: Tue Oct 27, 2015 7:02 pm
Location: De Steeg
Contact:

Re: Inter-instrument communication

#58 Post by Ralph »

This all started the get off topic, so I've closed it. A new one can be started if there are still questions.

Locked