Demon Posted December 18, 2016 Report Posted December 18, 2016 Solution: To transfer data between Lua threads use ipc.set and ipc.get. Hi, I searched the forum but can't find information relating with this. Can't we use LVARs to pass data between LUA scripts? Stumped with an impasse in my code, I did a small test: ipcready.lua ipc.macro("Lua WriteLvar") ipc.macro("Lua ReadLvar") WriteLvar.lua XYZVariable = 9 ipc.writeLvar("L:XYZ_Variable1",XYZVariable) ReadLvar.lua ipc.sleep(1000) if ipc.readLvar("L:XYZ_Variable1") == nil then XYZVariable = "nil" else XYZVariable = ipc.readLvar("L:XYZ_Variable1") end L:XYZ_Variable1 is always read back as nil? I put a short delay in Read just to be sure Write had time to finish. WriteLvar.log ********* LUA: "WriteLvar" Log [from FSUIPC version 4.958] ********* 44953 System time = 18/12/2016 13:33:44, Simulator time = 13:33:25 (17:33Z) 44953 LUA: beginning "E:\Steam\steamapps\common\FSX\Modules\WriteLvar.lua" 44953 LUA: E:\Steam\steamapps\common\FSX\Modules\WriteLvar.lua:1 44969 LUA: Global: ipcPARAM = 0 44969 LUA: E:\Steam\steamapps\common\FSX\Modules\WriteLvar.lua:3 44969 LUA: Global: XYZVariable = 9 44969 LUA: ended "E:\Steam\steamapps\common\FSX\Modules\WriteLvar.lua" 44969 System time = 18/12/2016 13:33:44, Simulator time = 13:33:25 (17:33Z) ********* LUA execution terminated: Log Closed ********* ReadLvar.log ********* LUA: "ReadLvar" Log [from FSUIPC version 4.958] ********* 45984 System time = 18/12/2016 13:33:45, Simulator time = 13:33:26 (17:33Z) 45984 LUA: beginning "E:\Steam\steamapps\common\FSX\Modules\ReadLvar.lua" 45984 LUA: E:\Steam\steamapps\common\FSX\Modules\ReadLvar.lua:1 45984 LUA: Global: ipcPARAM = 0 47000 LUA: E:\Steam\steamapps\common\FSX\Modules\ReadLvar.lua:3 47000 LUA: E:\Steam\steamapps\common\FSX\Modules\ReadLvar.lua:4 47000 LUA: E:\Steam\steamapps\common\FSX\Modules\ReadLvar.lua:7 47000 LUA: Global: XYZVariable = nil 47000 LUA: ended "E:\Steam\steamapps\common\FSX\Modules\ReadLvar.lua" 47000 System time = 18/12/2016 13:33:46, Simulator time = 13:33:27 (17:33Z) ********* LUA execution terminated: Log Closed ********* Or am I wrong in my understanding of how LVARs work? I know I can read them just fine from XML gauges. The other part that confuses me a bit are the work variables we create in the LUAs; they are defined as GLOBAL in the logs. That to me would mean they could be accessed from any LUA script, but I'm sure I'm wrong about that too. Robert
Pete Dowson Posted December 18, 2016 Report Posted December 18, 2016 2 hours ago, Demon said: I searched the forum but can't find information relating with this. Can't we use LVARs to pass data between LUA scripts? Seems doubtful to me. In the example you give it is evident that the LVar you are trying to read and write does not exist. You can't create LVars, only access whatever LVars the gauges you are using themselves create. It does say quite clearly in the Lua library documentation: "If the variable is not currently available, nothing happens" and the nil return to the read also shows that it doesn't exist. Even if you did it with an already existing LVar, the gauge decides what happens to that LVar, not you. The value could be changed after you try to write it. After all, they tend to represent things controlled by or supplied by the gauges themselves. To transfer data between Lua threads use ipc.set and ipc.get. That's what they are for! And with the most recent FSUIPC versions this even works over a Network between FSUIPC and WideFS clients, and between the clients themselves! Pete 1
Demon Posted December 18, 2016 Author Report Posted December 18, 2016 That's weird. I've been creating my own LVARs in LUA scripts for days now, and then using them in XML gauges. I'm careful to use unique LVARs too. Taken from FSX SDK: Quote Local Parameters (L:) When a local parameter is declared, its value is set to zero. Use your own names for these parameters, but care should be taken that these names are unique. I'm going to go check out Set and Get, thanks! Robert
Demon Posted December 19, 2016 Author Report Posted December 19, 2016 I also tried setting the LVAR directly in a MACRO as you instruct in the manual from a button on my CH thruster quadrant. I pass a 1 on Press, 0 on Release. That didn't work either? [Macros] 1=L:KK_MipButAutolandTest1=Set My goal is to simulate the Autoland Indicator on the Captain's panel for the Level-D 767. I can read the status of Autoland System thanks to the offsets from Nico and have the annunciators lit just like the real one (bigger, brighter, old eyes) I'd just like to do those two freaking test buttons light up the annunciators and I can't get that "bridge" happening. Robert
Pete Dowson Posted December 19, 2016 Report Posted December 19, 2016 22 minutes ago, Demon said: That's weird. I've been creating my own LVARs in LUA scripts for days now Hmm. Strange. I've never been able to. What happened in your example above, then? 23 minutes ago, Demon said: and then using them in XML gauges Ah, so it will have been the XML gauge which got them created! 13 minutes ago, Demon said: I also tried setting the LVAR directly in a MACRO as you instruct in the manual from a button on my CH thruster quadrant. I pass a 1 on Press, 0 on Release. That didn't work either? [Macros] 1=L:KK_MipButAutolandTest1=Set And does that variable exist beforehand? And if so, does the gauge concerned allow this? And is the button being held long enough? Try using some separate LVar logging, like the Lua plug-in supplied with FSUIPC, to see what's happening. I'm not sure how this later comment really relates to your earlier need to communicating values between plug-ins, which is definitiely a facility explicitly implemented in the library. Pete 1
Demon Posted December 19, 2016 Author Report Posted December 19, 2016 I've been trying different ways 1 hour ago, Pete Dowson said: ...not sure how this later comment really relates to your earlier need to communicating values between plug-ins, which is definitiely a facility explicitly implemented in the library. I've been trying various ways to affect that LVAR. It's only to be used to pass data between LUAs. It doesn't exist in a gauge, which explains why it doesn't get "officially" created within FS-X. It was only as I was eating supper that I realized the same rule most likely applied; the LVAR will be treated the same for both FSUIPC LUA scripts and MACROs. I'll be using Set and Get, since this is exactly why you created these functions in the first place. Thanks for your time Pete! Robert Not as dumb as yesterday but stupider than tomorrow!
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now