function thr_psn(psn)
if psn >33 then
fsx_event("RUDDER_LEFT")
end
fsx_variable_subscribe("GENERAL ENG THROTTLE LEVER POSITION:1", "percent",
thr_psn)
i want to actually trigger rudder with each application of throttle
cant figure out in lua how to compare the new value of variable with last one
looking forward for quick guide plz
regards
maak
maak_pk wrote: ↑Mon Dec 14, 2020 6:18 am
hi thanks for a quick reply
i need to understand how can i store my thr_psn in two different variables with every change in it
Hi,
You are storing to two variables before the old value becomes equal to the new value. To measure change at some point both variables must be equal.
old_val=1
new_val=1
change_var=""
function compare(dir)
new_val=new_val+dir
if new_val >= old_val then change_var="Greater Value" else change_var="Lesser Value" end
old_val=new_val
print("The Value is a "..change_var)
end
fsx_variable_subscribe("GENERAL ENG THROTTLE LEVER POSITION:1", "percent", compare)
end)
If you have two data sources that is something different.
Keith
Last edited by Keith Baxter on Mon Dec 14, 2020 8:35 am, edited 2 times in total.
old_val=1
new_val=1
change_var=""
function compare(val)
new_val=new_val+val
if old_val >= new_val then change_var="Greater Value" else change_var="Lesser Value" end
old_val=new_val
print("The Value is a "..change_var)
print(new_val)
print("old"..old_val)
print("val"..val)
end
fsx_variable_subscribe("GENERAL ENG THROTTLE LEVER POSITION:1", "percent", compare)
That is because you print statement is after old_val =new_val but before the event is firing the callback
Put the print statement before and you will see different values.
old_val=1
new_val=1
change_var=""
function compare(val)
new_val=val
if new_val >= old_val then change_var="Greater Value" else change_var="Lesser Value" end
print(new_val)
print("old"..old_val)
print("val"..val)
old_val=new_val
print("The NEW Value is a "..change_var)
end
fsx_variable_subscribe("GENERAL ENG THROTTLE LEVER POSITION:1", "percent", compare)
local old_val = 200
function compare(val)
if val > old_val and old_val < 200 then
—do increasing stuff here
elseif val < old_val and old_val < 200 then
—do decreasing stuff here
end
old_val = val
end
fsx_variable_subscribe("GENERAL ENG THROTTLE LEVER POSITION:1", "percent", compare)