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

small table with index


Question

Posted

I want to build an array with data as in local tb ={1=a,2=b,3=c} and so on.

 

one question,

1 - I notice that i cant add a number as the index as above? unless i am doing something wrong?

 

Recommended Posts

  • 0
Posted

k,k  => k,v ?

 

  • 0
  • Inquirer
  • Posted
    2 minutes ago, jgab said:

    k,k  => k,v ?

     

    Thank you @jgab yes that worked, it messing with the sort but as i am only using it for a lookup and return value am I correct that I dont have to worry about that? all keys and values are unique.

     

     

    1 hour ago, jgab said:

    What error do you get?

    not sure if this was also posted

     

    re the error i have 5 sheets in the qa in one of the sheets i get this error

    attempt to call a nil value (global 'create2wayTable')

     

    however on another sheet it does work!

    • 0
  • Inquirer
  • Posted (edited)

    i have made a function as:

     

    function createTempTable(year)

    i then populate the table based on the year variable which i pass in.

    as local pTb = create2wayTable()

    local pIx = 1

    pTb.add(pIx,"one")

    pIx = pIx +1

    pTb.add(pIx,"two")

    and so on, the reason why i am using pIx is because depending on the variable passed in the funtion it will then build a different table for the year.

     

    the table is being built properly and i can debug it from with in the function by,

    for k,v in pairs(pTb.tab) do print(k,v) end.

     

    so my question is how do i refernece this table in order to make use of the key and value in it please?

    from another function i want to call this table and then be able to get either the index or the value, but am a bit stuck on how do that?

     

    can you guide me please?

     

    after a bit of firther messing i have done this:

    in the create2way function

    return pTb

     

    and then in the first function:

    pYear = createTempTable(year) 

     

    local getB= pYear.lookupKey("Bee")

     

    which returns me 2

     

    i assume this is the correct way of doing it?

     

     

    Edited by Jay Ess

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