Jump to content
Sign in to follow this  
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
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

[CPL]  I9-9900K @5.0GHz HT ON, Maximus XI Hero, ASUS TUF RTX4080 OC, 32GB DDR4 3200 14, 1TB NVMe SSD, 500GB SSD, 1TB HDD, 40" Samsung 4K TV, Honeycomb Alpha & Bravo, Logitech Rudder Pedals, WIN11

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

Bert

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


Bert

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

[CPL]  I9-9900K @5.0GHz HT ON, Maximus XI Hero, ASUS TUF RTX4080 OC, 32GB DDR4 3200 14, 1TB NVMe SSD, 500GB SSD, 1TB HDD, 40" Samsung 4K TV, Honeycomb Alpha & Bravo, Logitech Rudder Pedals, WIN11

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

[CPL]  I9-9900K @5.0GHz HT ON, Maximus XI Hero, ASUS TUF RTX4080 OC, 32GB DDR4 3200 14, 1TB NVMe SSD, 500GB SSD, 1TB HDD, 40" Samsung 4K TV, Honeycomb Alpha & Bravo, Logitech Rudder Pedals, WIN11

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
Sign in to follow this  
  • Tom Allensworth,
    Founder of AVSIM Online


  • Flight Simulation's Premier Resource!

    AVSIM is a free service to the flight simulation community. AVSIM is staffed completely by volunteers and all funds donated to AVSIM go directly back to supporting the community. Your donation here helps to pay our bandwidth costs, emergency funding, and other general costs that crop up from time to time. Thank you for your support!

    Click here for more information and to see all donations year to date.
×
×
  • Create New...