Bálint Szarka Posted Saturday at 04:27 PM Report Posted Saturday at 04:27 PM Hi everyone, I am coming here to ask for guidance as a newbie in writing a lua script that would accomplish a very simple task. My intention is to have a lua script that would check whether the engine anti ice in four engine aircraft (FBW A380 ) is ON, and if so then either leave it ON or turn it OFF based on which button I press. My current script doesn't seem to work, and I get the following error in the FSUIPC7.log 18391 *** LUA Error: E:\FSUIPC7\LuaFiles\FBW_TEST.lua:3: '<name>' expected near '"XMLVAR_MOMENTARY_PUSH_OVHD_ANTIICE_ENG1_PRESSED"' My LUA script is the following: function engantiice() val1 = ipc.readLvar(L:"XMLVAR_MOMENTARY_PUSH_OVHD_ANTIICE_ENG1_PRESSED") val2 = ipc.readLvar(L:"XMLVAR_MOMENTARY_PUSH_OVHD_ANTIICE_ENG2_PRESSED") val3 = ipc.readLvar(L:"XMLVAR_MOMENTARY_PUSH_OVHD_ANTIICE_ENG3_PRESSED") val4 = ipc.readLvar(L:"XMLVAR_MOMENTARY_PUSH_OVHD_ANTIICE_ENG4_PRESSED") if val1 == 1 then ipc.execPreset("A380X_OH_ANTIICE_ENG1_TOG", 0) end if val2 == 1 then ipc.execPreset("A380X_OH_ANTIICE_ENG2_TOG", 0) end ipc.sleep(700) if val3 == 1 then ipc.execPreset("A380X_OH_ANTIICE_ENG3_TOG", 0) end if val4 == 1 then ipc.execPreset("A380X_OH_ANTIICE_ENG4_TOG", 0) end end Could anyone explain to me in a very simplified language on what am I doing wrong here? Please note I am far away from being a programmer of any kind. I am just trying to learn this. I have watched some videos on how to write a conditional LUA script but those are never ever dealing with flight sim and variables etc, so it's difficult for me to put in perspective when it comes flight sim and its related differences. I would appreciate if someone could chime in and say what's wrong above? Thank you so much, Balint Szarka
John Dowson Posted Saturday at 05:36 PM Report Posted Saturday at 05:36 PM 1 hour ago, Bálint Szarka said: val1 = ipc.readLvar(L:"XMLVAR_MOMENTARY_PUSH_OVHD_ANTIICE_ENG1_PRESSED") val2 = ipc.readLvar(L:"XMLVAR_MOMENTARY_PUSH_OVHD_ANTIICE_ENG2_PRESSED") val3 = ipc.readLvar(L:"XMLVAR_MOMENTARY_PUSH_OVHD_ANTIICE_ENG3_PRESSED") val4 = ipc.readLvar(L:"XMLVAR_MOMENTARY_PUSH_OVHD_ANTIICE_ENG4_PRESSED") The L: needs to be in the quotes, i.e. Quote val1 = ipc.readLvar("L:XMLVAR_MOMENTARY_PUSH_OVHD_ANTIICE_ENG1_PRESSED") val2 = ipc.readLvar("L:XMLVAR_MOMENTARY_PUSH_OVHD_ANTIICE_ENG2_PRESSED") val3 = ipc.readLvar("L:XMLVAR_MOMENTARY_PUSH_OVHD_ANTIICE_ENG3_PRESSED") val4 = ipc.readLvar("L:XMLVAR_MOMENTARY_PUSH_OVHD_ANTIICE_ENG4_PRESSED") John
Bálint Szarka Posted Saturday at 06:23 PM Author Report Posted Saturday at 06:23 PM 46 minutes ago, John Dowson said: The L: needs to be in the quotes, i.e. John Thank you so much. I will give it a try.
Bálint Szarka Posted Saturday at 06:31 PM Author Report Posted Saturday at 06:31 PM @John Dowson do you think that you would be able to pin point me towards a direction where I can figure out how can I continuously keep checking until a condition is met?
John Dowson Posted Saturday at 08:34 PM Report Posted Saturday at 08:34 PM 1 hour ago, Bálint Szarka said: do you think that you would be able to pin point me towards a direction where I can figure out how can I continuously keep checking until a condition is met? Use the while construct - from https://www.tutorialspoint.com/lua/lua_while_loop.htm: Quote Syntax The syntax of a while loop in Lua programming language is as follows − while(condition) do statement(s) end Here, statement(s) may be a single statement or a block of statements. The condition may be any expression, and true is any non-zero value. The loop iterates while the condition is true. The do statement can be a sleep (e.g. ipc.sleep(25)) to wait a short time to not consume so many resources and to give time to other threads so that the condition can become true. The loop will exit and the lua code continue when the statement is true. Such a loop is useful in many circumstances, for example to wait for an lvar to become available (not all lvars are initially available!), use: -- Check Lvar exists id = ipc.getLvarId("L:FS2CEW_RAASPRO_MASTER_SWITCH") while ( id == nil or id > 65535 or id < 0) -- Note that just a nil check should be sufficient from 7.5.2 onwards do ipc.reloadWASM() -- request to scan for new lvars ipc.sleep(200) -- wait before checking again id = ipc.getLvarId("L:FS2CEW_RAASPRO_MASTER_SWITCH") end -- lvar now available By the way, no need to tag me - I read all posts anyway! Cheers, John
Bálint Szarka Posted Saturday at 08:48 PM Author Report Posted Saturday at 08:48 PM 13 minutes ago, John Dowson said: Use the while construct - from https://www.tutorialspoint.com/lua/lua_while_loop.htm: The do statement can be a sleep (e.g. ipc.sleep(25)) to wait a short time to not consume so many resources and to give time to other threads so that the condition can become true. The loop will exit and the lua code continue when the statement is true. Such a loop is useful in many circumstances, for example to wait for an lvar to become available (not all lvars are initially available!), use: -- Check Lvar exists id = ipc.getLvarId("L:FS2CEW_RAASPRO_MASTER_SWITCH") while ( id == nil or id > 65535 or id < 0) -- Note that just a nil check should be sufficient from 7.5.2 onwards do ipc.reloadWASM() -- request to scan for new lvars ipc.sleep(200) -- wait before checking again id = ipc.getLvarId("L:FS2CEW_RAASPRO_MASTER_SWITCH") end -- lvar now available By the way, no need to tag me - I read all posts anyway! Cheers, John Thanks for the tip. Sorry for the tag, I learn on the go.
John Dowson Posted Sunday at 11:44 AM Report Posted Sunday at 11:44 AM 14 hours ago, Bálint Szarka said: Sorry for the tag, I learn on the go. No need to be sorry - you can still tag me, its just that its generally not necessary as I read all posts on these forums anyway! John
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