February 11, 20179 yr Hi, I am trying to increase the value of my Lvar in increments of 6 from 0-354 Whats the LUA code for this as my existing code results in an error saying that I am trying to perform arithmetic on a string. Here's what I wrote function AltPlusSlow () if ipc.readLvar("name") == 354 then ipc.writeLvar("name", 0) else ipc.writeLvar ("name" +6) end end thanks for looking Cheers Stinger
February 11, 20179 yr Hi Stinger It is good practice to carry out any computation (calculations) within the function rather than read and write data directly to Lvars. Variables should also be declared local so they do not risk impacting other parts of your code. This function assumes that the 'alt_value' is numerical. function AltPlusSlow() local var = ipc.readLvar("alt_value") if var >= 354 then var = 0 else var = var + 6 end ipc.writeLvar("alt_value", val) end Andrew Gransden Scotland, UK LINDA Support/Developer - VATSIM and BAVirtual - Airbus Flyer i7 1TB SSD GTX980 - FSX/P3D - Aerosoft Airbus A318/A319/A320/A321 - FS2Crew
February 11, 20179 yr Author Hi, Many thanks for the prompt reply. I'll give it a go and let you know. regards Stinger
February 11, 20179 yr Author Okay, getting closer.... the Lvar is now increasing and decreasing in increments of 6 but it stops at 354 on the increase side and stops at 0 on the decrease side? Here's what I wrote........ ********************************************************************* function AltSelPlus () local var = ipc.readLvar("CUSTOM_AP_ALT_KNOB") if var >= 354 then var = 0 else var = var + 6 ipc.writeLvar("CUSTOM_AP_ALT_KNOB", var) end end function AltSelMinus () local var = ipc.readLvar("CUSTOM_AP_ALT_KNOB") if var <= 0 then var = 354 else var = var - 6 ipc.writeLvar("CUSTOM_AP_ALT_KNOB", var) end end ************************************************************************ As an additional problem, although the Lvar value is changing the altitude indicator is not ??? Does this mean there is some ipc.control going on too? If so, how do I check for this? REALLY appreciate your help on this, I have been struggling since yestersay morning. :smile: cheers Stinger Okay, I have now cured the stopping at 354 or 0 . I just need to sort out why the altitude is not changing on the main display. cheers Stinger
February 11, 20179 yr Remember what you are trying to do. A simple pencil and paper exercise is good for working it out. In your minus function you are trying to move anti-/counter-clockwise. Therefore the step before zeeo/360 degrees is +6 not 354. The test should be: If var <= 6 then var = 360 else var = var -6 end In some simulators there are 2 Lvars - one for indication and one for the knob. I suggest you study the code module for another aircraft and see how it does want you want to do. Remember this is a support Forum for LINDA not for learning programming. Andrew Gransden Scotland, UK LINDA Support/Developer - VATSIM and BAVirtual - Airbus Flyer i7 1TB SSD GTX980 - FSX/P3D - Aerosoft Airbus A318/A319/A320/A321 - FS2Crew
February 11, 20179 yr Author Hi again, I was actually close, it just needed a writeLvar in the middle of the function to set it to 0 when increasing from 354 and 354 when decreasing from zero. I take your point about this being a Linda support forum. I shall ask elsewhere in future. However I appreciate your reply. I had actually studied the other available modules before starting out but none of them seemed to have what I needed and after two days if head scratching I was getting desperate. ! Cheers Stinger
February 11, 20179 yr Sorry. I didn't spot where you placed the ipc.writeLvar statement. I have been looking at the screen all day and I am getting code blind. Andrew Gransden Scotland, UK LINDA Support/Developer - VATSIM and BAVirtual - Airbus Flyer i7 1TB SSD GTX980 - FSX/P3D - Aerosoft Airbus A318/A319/A320/A321 - FS2Crew
February 15, 20179 yr Okay, getting closer.... the Lvar is now increasing and decreasing in increments of 6 but it stops at 354 on the increase side and stops at 0 on the decrease side? Here's what I wrote........ ********************************************************************* function AltSelPlus () local var = ipc.readLvar("CUSTOM_AP_ALT_KNOB") if var >= 354 then var = 0 else var = var + 6 ipc.writeLvar("CUSTOM_AP_ALT_KNOB", var) end end function AltSelMinus () local var = ipc.readLvar("CUSTOM_AP_ALT_KNOB") if var <= 0 then var = 354 else var = var - 6 ipc.writeLvar("CUSTOM_AP_ALT_KNOB", var) end end ************************************************************************ As an additional problem, although the Lvar value is changing the altitude indicator is not ??? Does this mean there is some ipc.control going on too? If so, how do I check for this? REALLY appreciate your help on this, I have been struggling since yestersay morning. :smile: cheers Stinger Okay, I have now cured the stopping at 354 or 0 . I just need to sort out why the altitude is not changing on the main display. cheers Stinger Stinger, could you post your final version here? Thanks, Dirk.
Archived
This topic is now archived and is closed to further replies.