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.
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
- local friendsScoreTable = {};
- local friendsScoreText = {};
inside the for loop.
Thanks Rob and Barak.