Jump to content
The simFlight Network Forums

Lvar into Offsets


Recommended Posts

Hello. I have searched forum.simflight.com and other websites for examples but found no examples that worked. I am trying to read a Lvar and insert that value into an FSUIPC offset using the function.


--------  This works but not efficient  -------------

while 1 do

FDValue = ipc.readLvar("L:CpitCmdrSetValue")
ipc.writeSW(0x66F0,FDValue)
ipc.sleep(50)

end

----------- offset into lvar = works but need lvar into offset -----------

function PanelShow(offset, val)
    val = ipc.readSB(0x66C0)         
    ipc.writeLvar("L:PANELTYPE", val)
end

event.offset(0x66C0,"SB","PanelShow")

=====================================

The two examples below do not work: Why not?
-------------------------------------

function FDCmdrShow(offset, val)
    val = ipc.readLvar("L:CpitCmdrSetValue")         
    ipc.writeSW(0x66F0, val)
 end

event.offset(0x66F0,"SW","FDCmdrShow")

---------------------------------------

function fdcmdrvalue (LvarName,LvarValue)
    ipc.writeSW(0x66F0,LvarValue)
end

event.Lvar("CpitCmdrSetValue",100,"fdcmdrvalue")

==========================================

 

 

Link to comment
Share on other sites

16 hours ago, gr8guitar said:

function fdcmdrvalue (LvarName,LvarValue)
    ipc.writeSW(0x66F0,LvarValue)
end

event.Lvar("CpitCmdrSetValue",100,"fdcmdrvalue")

This is the correct way to add an lvar to an offset in FSUIPC4,5 and 6 (in FSUIPC7 there is an easier way). If that isn't working, I expect this is because the lvar doesn't exist when you are calling the event.Lvar function -  you can test for this using the ipc.getLvarId function, e.g.

function fdcmdrvalue (LvarName, LvarValue, userParam)
    ipc.writeSW(0x66F0, LvarValue)
end


id = ipc.getLvarId("CpitCmdrSetValue")
if id == nil then
    ipc.log("Lvar CpitCmdrSetValue doesn't exist!")
else
    event.Lvar("CpitCmdrSetValue", 100, "fdcmdrvalue")
end

Also, please try using the lua debugging facilities (using Debug/Trace Lua plugins from the Logging tab with Send to console window checked) to see what is occurring in your lua scripts. You can also take a look at your FSUIPC log file if the console window output scrolls too fast for you to read.

John

Link to comment
Share on other sites

Hello. I will give it a shot. The lvar exists as I mentioned, the "while 1 do..." works, just not efficient. I am logging but within FSUIPC's logging tab so I can see the value 66F0 change. It just didn't work when I attempted to use the function and event.Lvar. I will continue. Thank you for your time and information.

Link to comment
Share on other sites

1 minute ago, gr8guitar said:

The lvar exists as I mentioned, the "while 1 do..." works, just not efficient.

But that is in a loop. The lvar can be created after the loop starts, but the lvar will be read once it is available. With the event.lvar call, the lvar should be available when you call this (I think!), which is why I suggested adding that check.

3 minutes ago, gr8guitar said:

I am logging but within FSUIPC's logging tab so I can see the value 66F0 change.

That is the offset monitoring. Try the debug /trace lua plugins to see what is happening. With the information you provided, I do not even know if that lua script is running (or what FS or version of FSUIPC you are using)

If you want further assistance, please attach your lua file (not paste its contents), together with your FSUIPC ini and log files, the latter generated with logging for lua plugins enabled.

John

Link to comment
Share on other sites

Hello John. Will do. Again, thank you. Okay update John. I had to update! I was reading a post that stated event.Lvar wasn't available to v4.841. I was using v4484. Updated to v4.97a. I rarely update, unless something doesn't work. My primary FS is still FS2004! I have too much invested in FS2004 and its addons. I haven't tried event.Lvar in v3.999z. Thank you John (and Pete) for offering 3.999z keys for free. I did purchase v3 and 4 FSUIPC a long time ago but not WideFS (yet).

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use. Guidelines Privacy Policy We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.