Global variables

Help creating logic scripts for Air Manager Instruments

Moderators: russ, Ralph

Message
Author
Shimokuta
Posts: 113
Joined: Wed Feb 03, 2021 12:52 pm

Global variables

#1 Post by Shimokuta »

Hello

I am trying to use input from an encoder from one instrument (RMU) to set things on another (TCAS display)
I try to use global variables to do this, but it seems that gloabal variables only are written when they change??
Is this a fact?
I have tried many things but writing for instance encoder clicks are only written when the value change, f.i. when changing direction.

Code: Select all

local TCAS_enc = 1

TCAS_Enc_var = si_variable_create("TCAS ENC", "INT", 0) 

function ENC2(direction)
  
  TCAS_enc = direction
  si_variable_write(TCAS_Enc_var, TCAS_enc)
  
  if direction == 1 then 

	-- do stuff
	
  elseif direction == -1 then
    
	-- do stuff
  
  end
end
	
function TCAS_Range_enc_callback(data1)
   print("TCASE enc: ")
   print( data1)
       
end	

si_variable_subscribe("TCAS ENC", "INT", TCAS_Range_enc_callback)
hw_dial_add("ARDUINO_UNO_A_D11", "ARDUINO_UNO_A_D12", ENC2)
Any sugestions how to send continuesly encoder data for this use from one instrument to another?

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

Re: Global variables

#2 Post by Ralph »

Instruments do not share resources and variables. If you want to get data across from one to the other, then you have to use inter instrument communication:
https://siminnovations.com/wiki/index.p ... munication

Note that this data runs through the plugin, so it only works when the flight simulator is connected.

Shimokuta
Posts: 113
Joined: Wed Feb 03, 2021 12:52 pm

Re: Global variables

#3 Post by Shimokuta »

Hi Ralph

Yes i know, that is what i am trying to do,

si_variable_write(TCAS_Enc_var, TCAS_enc)

This usually works fine when i subscribe to the variable in another instrument, but when using an encoder it seems to only update the variable once until in this case the direction changes.
But also if i send from within the encoder function more global varables they also are not being updated.

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

Re: Global variables

#4 Post by Ralph »

The encoder callback is only called when the recorder is rotated. So I'm not really sure what the problem is...? That's normal behavior.

Shimokuta
Posts: 113
Joined: Wed Feb 03, 2021 12:52 pm

Re: Global variables

#5 Post by Shimokuta »

In my code added i try to write every time the function of the encoder is started a value to a global variable.
But as long as the encoder turns clockwise (or counter clickwise) there is only 1 time a global value written.
I would suspect that with every click (like in a normal situation where the encoder is defined in the instrument) i would get a writing to the global value so multiple changes on the global value?

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

Re: Global variables

#6 Post by Ralph »

You will have to use a command and command subscribe for that.
Place this in your encoder callback:
https://siminnovations.com/wiki/index.p ... Si_command
With a command for up and down, then subscribe to these commands in the other instrument.
https://siminnovations.com/wiki/index.p ... _subscribe

Shimokuta
Posts: 113
Joined: Wed Feb 03, 2021 12:52 pm

Re: Global variables

#7 Post by Shimokuta »

Ok thanks ralph

Will try that!!

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

Re: Global variables

#8 Post by Ralph »

Let us know if you need an example script.

Shimokuta
Posts: 113
Joined: Wed Feb 03, 2021 12:52 pm

Re: Global variables

#9 Post by Shimokuta »

Yes if you have an example script that would be great!!

thx

Shimokuta
Posts: 113
Joined: Wed Feb 03, 2021 12:52 pm

Re: Global variables

#10 Post by Shimokuta »

I made an easy fix for my issue.
I declared the encoder in two instruments and send a global variable from the first, where the encoder is present , to the second, where my tcas range should change.
So only when on my rmu the tcas range is selected this instrument sends a true value to the second where lua code changes stuff…

I will upload a video … (can imagine this is unclear)

Post Reply