Jump to content

Welcome to Smart Home Forum by FIBARO

Dear Guest,

 

as you can notice parts of Smart Home Forum by FIBARO is not available for you. You have to register in order to view all content and post in our community. Don't worry! Registration is a simple free process that requires minimal information for you to sign up. Become a part of of Smart Home Forum by FIBARO by creating an account.

 

As a member you can:

  •     Start new topics and reply to others
  •     Follow topics and users to get email updates
  •     Get your own profile page and make new friends
  •     Send personal messages
  •     ... and learn a lot about our system!

 

Regards,

Smart Home Forum by FIBARO Team


  • 0

var or local var


Question

Posted

Is there any difference in scenes or VDs between

  a= 3

  b= 2

  c= a+b

and

  local a= 3

  local b= 2

  local c= a+b

?

Thanks!

 

3 answers to this question

Recommended Posts

  • 0
Posted

You need a bit more code to see a difference, you need a "block". See:

Please login or register to see this link.

Because a scene or a VD is a unit on its own, you won't notice a difference at the main level. But technically speaking, you should use "local". When you are using variables in a function or in a if-then-else-end the difference is important. It's explained after that link.

  • 0
  • Inquirer
  • Posted

    Thanks Petergebruers,

     

    I bought Ierusalimschy's book immediately, inside outside a function is now clear.

     

    There is a new question: what do you mean with 'But technically speaking, you should use "local".' (at the main level) ?

    Does the code run faster or does it need less ressources with 'local var' than without ?

     

    Thank you!

    • 0
    Posted

    On an HC2 it doesn't make a difference. I'm not fanatic about using "local" at the main level. It can make a difference on other platforms. If you want to experiment with Lua, you can try the excellent multi-platform "ZeroBrane Studio".

    Please login or register to see this link.

    Join the conversation

    You can post now and register later. If you have an account, sign in now to post with your account.

    Guest
    Answer this question...

    ×   Pasted as rich text.   Paste as plain text instead

      Only 75 emoji are allowed.

    ×   Your link has been automatically embedded.   Display as a link instead

    ×   Your previous content has been restored.   Clear editor

    ×   You cannot paste images directly. Upload or insert images from URL.

    ×
    ×
    • Create New...