bokdany

How to store a value in Local variable (L:) in Lua ?

Recommended Posts

Hi, I trying to store a simple value in a local variable in the following Lua code.

the code:

!Lua 

-- get the L:var value
local val = varget("L:myVar","Number") 

val = val + 1 

-- store value in L:var
varset("L:myVar","Number",val)

 

This code is used for material scripting (P3D v4.2) but it's seems doesn't work.

Is it possible to store a new value in a local variable and re-read it  at each execution of this code?

Thanks by advance.

Share this post


Link to post
Help AVSIM continue to serve you!
Please donate today!

local val = varget("L:myVar","Number") 

should be

val = varget("L:myVar","Number") 


varset("L:myVar","Number",val) 

should be 

varset("L:myVar”,val)
Edited by bbuckley
  • Like 1

Share this post


Link to post

Hello buckley, thanks for your quick answer, but I tried and it does not work, so I have a question, do I have to instantiate (L: myVar) before trying to get its value and if so where?

Share this post


Link to post

L variables are set to zero by default.. so the first varget should get you zero.

You can set it:

varset("L:myVar",0)

 

Edited by Bert Pieke

Share this post


Link to post
18 hours ago, bbuckley said:

varset("L:myVar”,val)

This varset statement has two different quote marks... " "

Could be a problem if copied/pasted

Share this post


Link to post
3 hours ago, Bert Pieke said:

This varset statement has two different quote marks... " "

Could be a problem if copied/pasted

My bad. I copied and pasted OPs text and didn’t notice the different quotes. 

@bokdany make sure you correct that in both statements. 

Edited by bbuckley

Share this post


Link to post

Looking at it again zoomed, I think the second quote came from my iPad in the reply box. In any event, just type them both correctly in your text editor. 

Edited by bbuckley

Share this post


Link to post

Thanks alot for your replies, but  i think that i have a another kind of problem because i did many different try without results,   this script is called by a material who normally can access to local variables but its seems that i can read and write within some material variables and some simulation variables but not in local variables. I precise that i use P3D v4 with sdk 4.4.16.27106.

Edited by bokdany

Share this post


Link to post

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 account

Sign in

Already have an account? Sign in here.

Sign In Now