Cockpitbuilders.com

LUA Projects => General Discussions => Topic started by: Stinger2k2 on February 11, 2017, 06:41:26 AM

Title: How to increase an Lvar value by 6 or -6 ? - ANSWERED
Post by: Stinger2k2 on February 11, 2017, 06:41:26 AM
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.

Heres 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
Title: Re: How to increase an Lvar value by 6 or -6 ?
Post by: Stinger2k2 on February 13, 2017, 12:40:22 AM
Okay now,
A kind fellow on another forum helped me sort it out.
It just needed me to write in a local var.
The code now looks something like this....

function AltPlusSlow
local var = ipc.readLvar("name")
   if var = 354 then
ipc.writeLvar("name", 0)
else
var = var +6
ipc.writeLvar("name", var)
end
end

Sorry for sounding like a coding newbie but
that's exactly what I am !! lol.
cheers
Stinger
Title: Re: How to increase an Lvar value by 6 or -6 ? - ANSWERED
Post by: Trevor Hale on February 13, 2017, 03:16:14 AM
Don't be sorry. We all appreciate you posting your answers here.


Thank you.