Issue in showing Facebook friends scores

I’m using the following code inside my Facebook listener to show Facebook friends scores. The printTable(data) command shows the event.response table informations with no problem in the log screen, but I can’t manage to display them in the device screen.

Is there something wrong within my code?

[lua]

–…

 elseif ( “request” == event.type ) then

   local response = event.response

  response = json.decode( event.response )

  local data = response.data

  printTable(data)

  for i=1, #data, 1 do

   friendsScoreTable[i].name = data[i].user.name;

   friendsScoreTable[i].score = data[i].score;

   friendsScoreText[i] = display.newText(friendsScoreTable[i].name … "   " … friendsScoreTable[i].score, 0, 0, “ARIBLK”, 16);

   if(i==1)then

     friendsScoreText[i].x, friendsScoreText[i].y = centerX, centerY;

   else

    friendsScoreText[i].x, friendsScoreText[i].y = friendsScoreText[i-1].x, friendsScoreText[i-1].y+20;

   end

    localGroup:insert(friendsScoreText[i]);

 end

end

[/lua]

what output does printTable actually produce? Or better yet can you do:

print( json.prettify( response ) )

and show us that output?

Rob

Yes, Rob. The outputs are as follows.

 -------------- generated by printTable(data)          [1] = table: 0xb92f14b0       {               [score] = 0               [user] = table: 0xb938b170               {                       [name] = Donna Alabdgffgjchj Lauman                       [id] = 100388403720382               }       }       [2] = table: 0xb92f3f70       {               [score] = 0               [user] = table: 0xb90838f0               {                       [name] = Carol Alabcdiccajbj Narayananwi                       [id] = 116443688777275               }       }       [3] = table: 0xb90783d8       {               [score] = 0               [user] = table: 0xb90a8fa0               {                       [name] = Jennifer Alabbhgihffie Wongsky                       [id] = 127264704359795               }       }       [4] = table: 0xb944bae0       {               [score] = 0               [user] = table: 0xb8e224c0               {                       [name] = Lisa Alabcbiddbgdi Bharambeescu                       [id] = 119158068505174               }       }  -------------- generated by print(json.prettify((data))  [{      "score":0,      "user":{        "name":"Donna Alabdgffgjchj Lauman",        "id":"100388403720382"      }    },{      "score":0,      "user":{        "name":"Carol Alabcdiccajbj Narayananwitz",        "id":"116443688777275"      }    },{      "score":0,      "user":{        "name":"Jennifer Alabbhgihffie Wongsky",        "id":"127264704359795"      }    },{      "score":0,      "user":{        "name":"Lisa Alabcbiddbgdi Bharambeescu",        "id":"119158068505174"      }    }]

Not enough, Rob?

What color is your background? You could be drawing black text on a black background or white text on a white background (which ever the default is). The default color for display.newText() is white unless you’ve changed it.

Rob

My background is a dark blue and display.newText() color is default.

Nothing wrong in my code? I tried printing friendsScoreText[i].text, but nothing is displayed in the debugger. Weird, isn’t it?

I’m surprised Corona isn’t spewing errors consider:

  for i=1, #data, 1 do     friendsScoreTable[i].name = data[i].user.name;     friendsScoreTable[i].score = data[i].score;

vs.

 for i=1, #data, 1 do friendsScoreTable[i] = {} friendsScoreTable[i].name = data[i].user.name; friendsScoreTable[i].score = data[i].score;

I don’t see where you’re telling friendsScoreTable[i] that it’s supposed to hold a table.

Rob

friendsScoreTable is created in the first lines of my code as “local friendsScoreTable = {}”.
I’m gonna test your correction and feedback about it soon. Thanks.

Didn’t got it to work, Rob.

The code I’ve written and the log within device that has been produced is presented in the screenshot below.

corona.png

As can be seen, the text that was supposed to be store inside friendsScoreText[1] is not printed in the log screen and it’s not being displayed on my device screen as well. Yet, data within data[1] is printed without any issue. 

Try to initialize friendsScoreText[1] as Rob suggested.

[lua]
friendsScoreText[1] = {name = data[1].user.name,
score = data[1].score}

[/lua]

It worked! You meant friendsScoreTable[1], right? haha

Now, I’ve got another issue I don’t understand.

If I call the tables as

[lua]

friendsScoreTable[1] = {name = data[1].user.name, score = data[1].score}

friendsScoreText[1] = display.newText(friendsScoreTable[1].name … "\n   " … friendsScoreTable[1].score, 0, 0, “ARIBLK”, 16);

friendsScoreTable[2] = {name = data[2].user.name, score = data[2].score}

friendsScoreText[2] = display.newText(friendsScoreTable[2].name … "\n   " … friendsScoreTable[2].score, 0, 0, “ARIBLK”, 16);

[/lua]

it displays the related names and scores of indexes 1 and 2.

However, if I try to generalize as I presented in my first post as

[lua]

for i=1, #data, 1 do

 local friendsScoreTable = {};

 local friendsScoreText = {};

 friendsScoreTable[i] = {name = data[i].user.name, score = data[i].score}

  friendsScoreText[i] = display.newText(friendsScoreTable[i].name … "\n   " … friendsScoreTable[i].score, 0, 0, “ARIBLK”, 16);

  if(i==1)then

   friendsScoreText[i].x, friendsScoreText[i].y = centerX, centerY;

  elseif(i>1)then

   friendsScoreText[i].x, friendsScoreText[i].y = centerX, friendsScoreText[i-1].y;

  end

  localGroup:insert(friendsScoreText[i]);

  print(friendsScoreText[1].text)

  print("\n" … friendsScoreText[2].text)

end

[/lua]

only name and score of index 1 is displayed.

Solved!

To be clear for all, my mistake was calling tables 

  1. local friendsScoreTable = {};
  2.  local friendsScoreText = {};

inside the for loop.

 

Thanks Rob and Barak. :slight_smile:

what output does printTable actually produce? Or better yet can you do:

print( json.prettify( response ) )

and show us that output?

Rob

Yes, Rob. The outputs are as follows.

 -------------- generated by printTable(data)          [1] = table: 0xb92f14b0       {               [score] = 0               [user] = table: 0xb938b170               {                       [name] = Donna Alabdgffgjchj Lauman                       [id] = 100388403720382               }       }       [2] = table: 0xb92f3f70       {               [score] = 0               [user] = table: 0xb90838f0               {                       [name] = Carol Alabcdiccajbj Narayananwi                       [id] = 116443688777275               }       }       [3] = table: 0xb90783d8       {               [score] = 0               [user] = table: 0xb90a8fa0               {                       [name] = Jennifer Alabbhgihffie Wongsky                       [id] = 127264704359795               }       }       [4] = table: 0xb944bae0       {               [score] = 0               [user] = table: 0xb8e224c0               {                       [name] = Lisa Alabcbiddbgdi Bharambeescu                       [id] = 119158068505174               }       }  -------------- generated by print(json.prettify((data))  [{      "score":0,      "user":{        "name":"Donna Alabdgffgjchj Lauman",        "id":"100388403720382"      }    },{      "score":0,      "user":{        "name":"Carol Alabcdiccajbj Narayananwitz",        "id":"116443688777275"      }    },{      "score":0,      "user":{        "name":"Jennifer Alabbhgihffie Wongsky",        "id":"127264704359795"      }    },{      "score":0,      "user":{        "name":"Lisa Alabcbiddbgdi Bharambeescu",        "id":"119158068505174"      }    }]

Not enough, Rob?

What color is your background? You could be drawing black text on a black background or white text on a white background (which ever the default is). The default color for display.newText() is white unless you’ve changed it.

Rob

My background is a dark blue and display.newText() color is default.

Nothing wrong in my code? I tried printing friendsScoreText[i].text, but nothing is displayed in the debugger. Weird, isn’t it?

I’m surprised Corona isn’t spewing errors consider:

  for i=1, #data, 1 do     friendsScoreTable[i].name = data[i].user.name;     friendsScoreTable[i].score = data[i].score;

vs.

 for i=1, #data, 1 do friendsScoreTable[i] = {} friendsScoreTable[i].name = data[i].user.name; friendsScoreTable[i].score = data[i].score;

I don’t see where you’re telling friendsScoreTable[i] that it’s supposed to hold a table.

Rob