Is there anyway I can retrieve a player’s position in a leaderboard by his score or id?
If there isn’t yet, there should be…
Why would a player want to list the top X players if he wouldn’t know how well is he ranked?
Is there anyway I can retrieve a player’s position in a leaderboard by his score or id?
If there isn’t yet, there should be…
Why would a player want to list the top X players if he wouldn’t know how well is he ranked?
Besides, how can I get my players’ id once they log in to corona cloud?
I successfully logged in using Facebook, I’m successfully submitting scores, but I would like to be able to know my players’ unique id…
You can get their id from the getMyProfile() API call.
Hey Rob, I don’t think getMyProfile() is currently documented enough for me to understand how to get an user ID.
Would you mind explaining it a little bit?
Thanks for your fast reply, btw
[lua]
local function gotMyProfile(event)
local response = event.response
print(response.first_name)
print(response.last_name)
print(response._id) – your ID
– there are other fields too. Look for a table dumping function like print_r() in the community code
– to see everything
end
Runtime:addEventListener(“MyProfile”, gotMyProfile)
coronaCloud.getMyProfile()
[/lua]
Something like that.
I tested this code but the event won’t trigger at all…
Are there any docs regarding this?
Hmm some how some of my code got outside the code box. Look at the corrected code above and try that.
I noticed it and it seems to be triggering now, but I’m trying to popup an alert telling me response._id and it simply won’t do it…
I’ll keep trying, though, as it seems I’m close to a solution, hehe
Yeah, my event is triggering correctly, but for some weird reason my response._id seems to be always nil
[lua]
function print_r ( t )
local print_r_cache={}
local function sub_print_r(t,indent)
if (print_r_cache[tostring(t)]) then
print(indent…"*"…tostring(t))
else
print_r_cache[tostring(t)]=true
if (type(t)==“table”) then
for pos,val in pairs(t) do
if (type(val)==“table”) then
print(indent…"["…pos…"] => “…tostring(t)…” {")
sub_print_r(val,indent…string.rep(" “,string.len(pos)+8))
print(indent…string.rep(” “,string.len(pos)+6)…”}")
elseif (type(val)==“string”) then
print(indent…"["…pos…’] => “’…val…’”’)
else
print(indent…"["…pos…"] => “…tostring(val))
end
end
else
print(indent…tostring(t))
end
end
end
if (type(t)==“table”) then
print(tostring(t)…” {")
sub_print_r(t," “)
print(”}")
else
sub_print_r(t," ")
end
print()
end
[/lua]
put that function near the top of your program and then inside the event handler do:
print_r(event)
and see what all it’s returning. It may not be response, but result or some other variable.
event.results._id is the right way…
You guys should really work in your docs, hehe
I wasn’t using docs, but looking at the source code:
Runtime:dispatchEvent({name=“MyProfile”, results=response})
Ergo my confusion. We are using “response” in the function but returning “results” as the array member name.
Besides, how can I get my players’ id once they log in to corona cloud?
I successfully logged in using Facebook, I’m successfully submitting scores, but I would like to be able to know my players’ unique id…
You can get their id from the getMyProfile() API call.
Hey Rob, I don’t think getMyProfile() is currently documented enough for me to understand how to get an user ID.
Would you mind explaining it a little bit?
Thanks for your fast reply, btw
[lua]
local function gotMyProfile(event)
local response = event.response
print(response.first_name)
print(response.last_name)
print(response._id) – your ID
– there are other fields too. Look for a table dumping function like print_r() in the community code
– to see everything
end
Runtime:addEventListener(“MyProfile”, gotMyProfile)
coronaCloud.getMyProfile()
[/lua]
Something like that.
I tested this code but the event won’t trigger at all…
Are there any docs regarding this?
Hmm some how some of my code got outside the code box. Look at the corrected code above and try that.
I noticed it and it seems to be triggering now, but I’m trying to popup an alert telling me response._id and it simply won’t do it…
I’ll keep trying, though, as it seems I’m close to a solution, hehe
Yeah, my event is triggering correctly, but for some weird reason my response._id seems to be always nil