Skip to content
View in the app

A better way to browse. Learn more.

The AVSIM Community

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

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

Featured Replies

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.
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

[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

  • Author

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?

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

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

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

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

  • Author

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

Archived

This topic is now archived and is closed to further replies.

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.