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

LUA QA | using variable from 1 function in another


Symbiot78
 Share

Question

So 

I have a function:

function QuickApp:button3_1_pressed()
self:updateView("label_1""text"" Alkove Valgt")
selected_button = "button_3_1"
end
 
I want to use that in another function but it doens't seem to carry the content of my 'selected_button' variable. I thought _not_ using local would let me store info in a variable for... later use?
 
function QuickApp:button2_1_pressed()
self:updateView("label_1""text""Åbner")
fibaro.debug("QUICKAPP368",selected_button)
if (selected_button == "button3_1_pressed"then
      --åben alkove
    function QuickApp:btn3_1_pressed()
    local url = "http://"..powerview_ip.."/api/shades/40999"
    fibaro.debug("QUICKAPP368",url)
....
...
....
Link to comment
Share on other sites

4 answers to this question

Recommended Posts

  • 0

Hi,

 

You can do this by declaring the variable in the QuickApp:onInit(). --> Declare self.selected_button = ""

 

function QuickApp:onInit()
 
self.selected_button = ""
 
end
 
function QuickApp:button3_1_pressed()
self:updateView("label_1""text"" Alkove Valgt")
self.selected_button = "button_3_1"
end

 

function QuickApp:button2_1_pressed()
self:updateView("label_1""text""Åbner")
fibaro.debug("QUICKAPP368",selected_button)
if (self.selected_button == "button3_1_pressed"then
      --åben alkove
    function QuickApp:btn3_1_pressed()
    local url = "http://"..powerview_ip.."/api/shades/40999"
    fibaro.debug("QUICKAPP368",url)
 
See also the Quick App manual 

Please login or register to see this link.

--> self
 
Hope this works for you.
Link to comment
Share on other sites

  • 0
On 7/21/2021 at 9:22 AM, Symbiot78 said:

So 

I have a function:

function QuickApp:button3_1_pressed()
self:updateView("label_1""text"" Alkove Valgt")
selected_button = "button_3_1"
end
 
I want to use that in another function but it doens't seem to carry the content of my 'selected_button' variable. I thought _not_ using local would let me store info in a variable for... later use?
 
function QuickApp:button2_1_pressed()
self:updateView("label_1""text""Åbner")
fibaro.debug("QUICKAPP368",selected_button)
if (selected_button == "button3_1_pressed"then
      --åben alkove
    function QuickApp:btn3_1_pressed()
    local url = "http://"..powerview_ip.."/api/shades/40999"
    fibaro.debug("QUICKAPP368",url)
....
...
....

It works with Lua globals (within the same QA, and as long as the QA doesn't restart).

However, you set it to "button_3_1" and test it against "button3_1_pressed"

 

Edited by jgab
Link to comment
Share on other sites

  • 0
2 hours ago, jgab said:

It works with Lua globals (within the same QA, and as long as the QA doesn't restart).

However, you set it to "button_3_1" and test it against "button3_1_pressed"

 

 

Reminder to myself: Don't overlook the obvious 🙃😁😁. Thanks for the lesson jgab 😃

Link to comment
Share on other sites

  • 0
  • Inquirer
  • thanks guys.. this helped me past 1 problem and on to another :-| - I did notice the wrong check when I was pulling out my hair :)

     

     

     

     

    Link to comment
    Share on other sites

    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.

     Share

    ×
    ×
    • Create New...