roarkr Posted October 7, 2011 Report Posted October 7, 2011 Hi, Is there anyone with some LUA programming experience who can propose a better and more effective way than my example below. I write the Lvars value to offsets in every loop , even when the LVars have not changed, but should instead only want to write to FSUIPC offsets when Lvars have been changed. regards, Roar Kristensen ------- while 1 do --store the value that is read from the NGX L:vars: mcpspdw = ipc.readLvar("ngx_SPDwindow") mcphdgw = ipc.readLvar("ngx_HDGwindow") mcpaltw = ipc.readLvar("ngx_ALTwindow") mcpvsw = ipc.readLvar("ngx_VSwindow") mcpcrs1w = ipc.readLvar("ngx_CRSwindowL") mcpcrs2w = ipc.readLvar("ngx_CRSwindowR") mcpatal = ipc.readLvar("ngx_MCP_ATArm") mcpfd1s = ipc.readLvar("ngx_MCP_FDLeft") mcpfd2s = ipc.readLvar("ngx_MCP_FDRight") mcpvnavl = ipc.readLvar("ngx_MCP_VNav") mcplnavl = ipc.readLvar("ngx_MCP_LNav") mcpvorl = ipc.readLvar("ngx_MCP_VORLock") mcpn1l = ipc.readLvar("ngx_MCP_N1") mcpspdl = ipc.readLvar("ngx_MCP_Speed") mcplvll = ipc.readLvar("ngx_MCP_LvlChg") mcphdgl = ipc.readLvar("ngx_MCP_HdgSel") mcpappl = ipc.readLvar("ngx_MCP_App") mcpalthl = ipc.readLvar("ngx_MCP_AltHold") mcpvsl = ipc.readLvar("ngx_MCP_VS") mcpcmdal = ipc.readLvar("ngx_MCP_CMDA") mcpcmdbl = ipc.readLvar("ngx_MCP_CMDB") mcpcswal = ipc.readLvar("ngx_MCP_CSWA") mcpcswbl = ipc.readLvar("ngx_MCP_CSWB") --write the stored value to 0x0000 format offsets that SIOC can read: ipc.writeUW("66C0", mcpcrs1w) ipc.writeUW("66C2", mcpspdw) ipc.writeUW("66C4", mcphdgw) ipc.writeUW("66C6", mcpaltw) ipc.writeUW("66C8", mcpvsw) ipc.writeUW("66CA", mcpcrs2w) ipc.writeUB("66CC", mcpfd1s) ipc.writeUB("66CD", mcpn1l) ipc.writeUB("66CE", mcpatal) ipc.writeUB("66CF", mcpspdl) ipc.writeUB("66D0", mcplvll) ipc.writeUB("66D1", mcpvnavl) ipc.writeUB("66D2", mcphdgl) ipc.writeUB("66D3", mcpappl) ipc.writeUB("66D4", mcpvorl) ipc.writeUB("66D5", mcplnavl) ipc.writeUB("66D6", mcpalthl) ipc.writeUB("66D7", mcpvsl) ipc.writeUB("66D8", mcpcswal) ipc.writeUB("66D9", mcpcmdal) ipc.writeUB("66DA", mcpcswbl) ipc.writeUB("66DB", mcpcmdbl) ipc.writeUB("66DC", mcpfd2s) ipc.sleep(50) end
Pete Dowson Posted October 7, 2011 Report Posted October 7, 2011 Is there anyone with some LUA programming experience who can propose a better and more effective way than my example below. I write the Lvars value to offsets in every loop , even when the LVars have not changed, but should instead only want to write to FSUIPC offsets when Lvars have been changed. All you need to do, for each value, is have a saved value, declared initially, outside of the loop, to something impossible for that value. Then see if it changed. For example, taking just one, your "mcphdgw", Before the while line put prevmcphdgw = -1 then within the loop: mcphdgw = ipc.readLvar("ngx_HDGwindow") if mcphdgw ~= prevmcphdgw then ipc.writeUW("66C4", mcphdgw) prevmcphdgw = mcphdgw end See? You are simply keeping copies of values written, and comparing them, so you don't write them again. I know it looks longer, but it will execute better because you are asking FSUIPC to do less. Regards Pete
roarkr Posted October 7, 2011 Author Report Posted October 7, 2011 OK, I understand your code. Now I can rewrite my LUA. Thanks for your fast feedback. Roar K
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