Strange behaviour in Lua. Trying to build a sorted list

The LargeList function did not quite suit my requirements. So I tried to build a custom sorted list by using a Lua script to manipulate a record with…

  • List of elements sorted in order
  • Map containing the scores of the elements

Am very new to the world of Lua scripting, so you need to bear with me.

I’m stuck because I cannot seem to do the simplest task of comparing A) the scores I stored in the map against B) the score of new key I passed into the Lua script.

for val in list.iterator(l) do
 i= i+ 1
 if (m[l[i]] > score) then

I know how silly it sounds, but whatever values I try, I cannot get the script to run actionA. For example,

  • m[l[i]] is 9 and score is 10 >>> actionB gets triggered
  • m[l[i]] is 11 and score is 10 >>> actionB gets triggered

Stored inside the record…

users = l

users::score = m

{ bins: 
   { users: [ 'userA' ],
     'users::score': { userA: '10' }

The score being stored in your example seems to a string. Did you really mean

    { 'users': ['userA']
       'users::score' : { 'userA': 10 }

– R

Somehow, I was comparing 2 strings. Both m[l[i]] and score.

if (m[l[i]] > score) then

Needed to convert both to numbers using tonumber. Conversion is not automatic.

Thanks! Glad it was resolved.