This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm that you accept these cookies being set.

Global variables and constants
#1
Hi! 

I am new to Lua and Logic Machine 4 (I do not have LM5), but trying to learn. 
I have a question I hope someone can help me with. 

I want to controll heating loads in my house, by turning these on and off to reduce peak power. 
I therefore need to define constants and variables that all scripts (resident, event and in user library) can find, I belive these are called "global". 
I belive the declaration of the constants and variables can be written like this: 

------------------Constants in the system (temperatures) ---------------------

T_s={
  comfort={kitchen=22, bathroom=24, hall=20},
  save={kitchen=18, bathroom=20, hall=18
}


--------Declaration of the variables in the system -----------

loads={
  vb={k=5, room='bathroom', ad='2/0/5', B=0, P=3000},
  vk={k=4, room='bathroom', ad='11/0/0' ,B=1, P=60, T=T_test.bathroom},
  po={k=3, room='kitchen', ad='11/0/4', B=0, P=800, T=T_test.kitchen},
  vf_gang={k=2, room='hall', ad='2/0/6', B=0, P=860, T=T_test.hall},
  vf_kj={k=1, room='kitchen', ad='11/0/2', B=0, P=15, T=T_test.kitchen}
  }



I have read something about storage.set(), but is this the only way to do it? If so, in what script? And I am going to use these values a lot, will I always have to write  storage.get()?
Or can I make a library in User Library and just define all constants and variables like above, and then they are "global"? 

Thank you for all help!
Reply
#2
You can add constants to common functions. Use storage for any variables that you want to read and write from multiple scripts. You can also use objects for this if you want to tune some algorithm parameters from UI.
Reply
#3
Related to this: Is there any difference in performance between using objects (e.g. above the KNX 32 range) and storage.get/set?


Sent from my iPhone using Tapatalk
Reply
#4
No performance difference. But you can put larger and more complex data (like Lua tables) into storage whereas you are limited to 250 bytes when using objects.
Reply
#5
Thanks
:-)


Sent from my iPhone using Tapatalk
Reply


Forum Jump: