Game Center : loadPlayerPhoto

I can’t position, scale or add my loaded player image to groups so they can be removed.

I’m trying to build upon the multiplayer sample and add player photos and aliases next to my scores.

I tried to pass the photo as a storyboard variable like all other GC data is passed around but I can’t manipulate the display object!?!?!

How do I get the players images the best way? 

Feels like my code is just a big bowl of spaghetti…

Can you post some of that spaghetti…  Show us where you are getting the image and where you’re trying to move it.

I cleaned up the sides of the spaghetti bowl…

Heres my onRowRender where i want the player to see their friends photo and alias. 

If I use my own id then I get my pic rendered on all rows but how do i handle multiple ids?

And I do have a few friends if it helps…

thanks.

function onRowRender( event ) local phase = event.phase local row = event.row local function roomListener(roomEvent) local function loadLocalPlayerListener(loadLocalPlayerEvent) storyboard.myPlayerId = loadLocalPlayerEvent.data.playerID end storyboard.gameNetwork.request("loadLocalPlayer", {listener = loadLocalPlayerListener}) friendsImage = roomEvent.data.photo friendsImage:setReferencePoint(display.CenterReferencePoint) friendsImage.x = 45 friendsImage.y = row.height \* 0.5 friendsImage.width = 70 friendsImage.height = 70 row:insert(friendsImage) end storyboard.gameNetwork.request( "loadPlayerPhoto",{ playerID = storyboard.friendsArray[row.index].playerID, size = "Small", listener = roomListener}) friendsName = display.newText(row, storyboard.friendsArray[row.index].alias, 0, 0, 0, 0, "Arial", 22) friendsName:setReferencePoint(display.CenterLeftReferencePoint) friendsName.x = row.width\*0.5 friendsName.y = row.height \* 0.5 friendsName:setTextColor(66, 66, 66, 255) end

Are you getting the photos you expect just that you can’t move them?

Are you getting errors in your console log?

That code throw an error " …attempt to index upvalue ‘friendsImage’ (a nil value)…", however if I just put my playerID as “G:123456789” then it fetch my image. 

This is the only thing that works…

[lua]

– Working but only fetch one playerPhoto ofcourse…

storyboard.gameNetwork.request( “loadPlayerPhoto”,{ playerID = “G:123456789”, size = “Small”, listener = roomListener})

friendsImage = roomEvent.data.photo

[/lua]

A couple of tests not workning…

[lua]

– Not working, trows the error above.

storyboard.gameNetwork.request( “loadPlayerPhoto”,{ playerID = storyboard.friendsArray[row.index].playerID, size = “Small”, listener = roomListener})

– Added the “s” to playerID, not working.

storyboard.gameNetwork.request( “loadPlayerPhoto”,{ playerIDs = storyboard.friendsArray[row.index].playerID, size = “Small”, listener = roomListener})

– wrapped in a table, not working

storyboard.gameNetwork.request( “loadPlayerPhoto”,{ playerID = {storyboard.friendsArray[row.index].playerID}, size = “Small”, listener = roomListener})

– Added the “s” to playerID and wrapped in a table, not working.

storyboard.gameNetwork.request( “loadPlayerPhoto”,{ playerIDs = {storyboard.friendsArray[row.index].playerID}, size = “Small”, listener = roomListener})

– tostring() just for test, not working

storyboard.gameNetwork.request( “loadPlayerPhoto”,{ playerID = tostring(storyboard.friendsArray[row.index].playerID), size = “Small”, listener = roomListener})

– tostring() just for test, wrapped in a table, not working.

storyboard.gameNetwork.request( “loadPlayerPhoto”,{ playerID = {tostring(storyboard.friendsArray[row.index].playerID)}, size = “Small”, listener = roomListener})

– tostring() just for test, added “s”  to playerID, not working

storyboard.gameNetwork.request( “loadPlayerPhoto”,{ playerIDs = tostring(storyboard.friendsArray[row.index].playerID), size = “Small”, listener = roomListener})

– tostring() just for test, added “s”  to playerID, wrapped in a table, not working.

storyboard.gameNetwork.request( “loadPlayerPhoto”,{ playerIDs = {tostring(storyboard.friendsArray[row.index].playerID)}, size = “Small”, listener = roomListener})

[/lua]

I have tried this way to with all of the above tests and not working…

[lua]

for i = 1, #storyboard.friendsArray, 1 do

storyboard.gameNetwork.request( “loadPlayerPhoto”,{ playerID = storyboard.friendsArray[row.index].playerID, size = “Small”, listener = roomListener})

end

[/lua]

And I have tried with everything above…

[lua]

– not working

friendsImage = roomEvent.data[row.index].photo

– not working

friendsImage = roomEvent.data.photo

[/lua]

I can’t think of any more ways to try getting their photos?!?!?!

What line is that upvalue error referring too?

Are you declaring friendsImage somewhere?

I forward reference the friendsImage at the top of my file, nothing strange there…

I don’t get an error if I only supply a single Id like “G:123456789” but if I try fetch my friends photos like I said above the terminal says upvalue on where I set the referencePoint. If I comment that out then the error is at the next line and so on until all references are commented out.

The problem is when trying to retrieve multiple images, how do we add G: ids for multiple friends when requesting “loadPlayerPhoto”? 

I’ve made a clean start with the multiplayer sample from github, added a forward reference for the friendsImage at the top of the scene (select-players-scene.lua ) then request player photo for my friends and add them to each row. Like I said, single GC id work but not multiple.

I would put in some print statements to see if:

storyboard.friendsArray[row.index].playerID  is not nil and the string you expect formatted correctly.

if storyboard.friendsArray[row.index] is a table

if row.index is a valid value

loadPlayerPhoto is one player at a time.  Your array idea should work.

Can you post some of that spaghetti…  Show us where you are getting the image and where you’re trying to move it.

I cleaned up the sides of the spaghetti bowl…

Heres my onRowRender where i want the player to see their friends photo and alias. 

If I use my own id then I get my pic rendered on all rows but how do i handle multiple ids?

And I do have a few friends if it helps…

thanks.

function onRowRender( event ) local phase = event.phase local row = event.row local function roomListener(roomEvent) local function loadLocalPlayerListener(loadLocalPlayerEvent) storyboard.myPlayerId = loadLocalPlayerEvent.data.playerID end storyboard.gameNetwork.request("loadLocalPlayer", {listener = loadLocalPlayerListener}) friendsImage = roomEvent.data.photo friendsImage:setReferencePoint(display.CenterReferencePoint) friendsImage.x = 45 friendsImage.y = row.height \* 0.5 friendsImage.width = 70 friendsImage.height = 70 row:insert(friendsImage) end storyboard.gameNetwork.request( "loadPlayerPhoto",{ playerID = storyboard.friendsArray[row.index].playerID, size = "Small", listener = roomListener}) friendsName = display.newText(row, storyboard.friendsArray[row.index].alias, 0, 0, 0, 0, "Arial", 22) friendsName:setReferencePoint(display.CenterLeftReferencePoint) friendsName.x = row.width\*0.5 friendsName.y = row.height \* 0.5 friendsName:setTextColor(66, 66, 66, 255) end

Are you getting the photos you expect just that you can’t move them?

Are you getting errors in your console log?

That code throw an error " …attempt to index upvalue ‘friendsImage’ (a nil value)…", however if I just put my playerID as “G:123456789” then it fetch my image. 

This is the only thing that works…

[lua]

– Working but only fetch one playerPhoto ofcourse…

storyboard.gameNetwork.request( “loadPlayerPhoto”,{ playerID = “G:123456789”, size = “Small”, listener = roomListener})

friendsImage = roomEvent.data.photo

[/lua]

A couple of tests not workning…

[lua]

– Not working, trows the error above.

storyboard.gameNetwork.request( “loadPlayerPhoto”,{ playerID = storyboard.friendsArray[row.index].playerID, size = “Small”, listener = roomListener})

– Added the “s” to playerID, not working.

storyboard.gameNetwork.request( “loadPlayerPhoto”,{ playerIDs = storyboard.friendsArray[row.index].playerID, size = “Small”, listener = roomListener})

– wrapped in a table, not working

storyboard.gameNetwork.request( “loadPlayerPhoto”,{ playerID = {storyboard.friendsArray[row.index].playerID}, size = “Small”, listener = roomListener})

– Added the “s” to playerID and wrapped in a table, not working.

storyboard.gameNetwork.request( “loadPlayerPhoto”,{ playerIDs = {storyboard.friendsArray[row.index].playerID}, size = “Small”, listener = roomListener})

– tostring() just for test, not working

storyboard.gameNetwork.request( “loadPlayerPhoto”,{ playerID = tostring(storyboard.friendsArray[row.index].playerID), size = “Small”, listener = roomListener})

– tostring() just for test, wrapped in a table, not working.

storyboard.gameNetwork.request( “loadPlayerPhoto”,{ playerID = {tostring(storyboard.friendsArray[row.index].playerID)}, size = “Small”, listener = roomListener})

– tostring() just for test, added “s”  to playerID, not working

storyboard.gameNetwork.request( “loadPlayerPhoto”,{ playerIDs = tostring(storyboard.friendsArray[row.index].playerID), size = “Small”, listener = roomListener})

– tostring() just for test, added “s”  to playerID, wrapped in a table, not working.

storyboard.gameNetwork.request( “loadPlayerPhoto”,{ playerIDs = {tostring(storyboard.friendsArray[row.index].playerID)}, size = “Small”, listener = roomListener})

[/lua]

I have tried this way to with all of the above tests and not working…

[lua]

for i = 1, #storyboard.friendsArray, 1 do

storyboard.gameNetwork.request( “loadPlayerPhoto”,{ playerID = storyboard.friendsArray[row.index].playerID, size = “Small”, listener = roomListener})

end

[/lua]

And I have tried with everything above…

[lua]

– not working

friendsImage = roomEvent.data[row.index].photo

– not working

friendsImage = roomEvent.data.photo

[/lua]

I can’t think of any more ways to try getting their photos?!?!?!

What line is that upvalue error referring too?

Are you declaring friendsImage somewhere?

I forward reference the friendsImage at the top of my file, nothing strange there…

I don’t get an error if I only supply a single Id like “G:123456789” but if I try fetch my friends photos like I said above the terminal says upvalue on where I set the referencePoint. If I comment that out then the error is at the next line and so on until all references are commented out.

The problem is when trying to retrieve multiple images, how do we add G: ids for multiple friends when requesting “loadPlayerPhoto”? 

I’ve made a clean start with the multiplayer sample from github, added a forward reference for the friendsImage at the top of the scene (select-players-scene.lua ) then request player photo for my friends and add them to each row. Like I said, single GC id work but not multiple.

I would put in some print statements to see if:

storyboard.friendsArray[row.index].playerID  is not nil and the string you expect formatted correctly.

if storyboard.friendsArray[row.index] is a table

if row.index is a valid value

loadPlayerPhoto is one player at a time.  Your array idea should work.