I’ve got a pretty bad cold and am medded-up quite a bit, so I pre apologize if I’m in coherent.
I’m taking a break to figure out why some of my enemies are going the wrong direction in my update to Turkeys Revenge (Free, iTunes http://itunes.apple.com/us/app/turkeys-revenge/id481579390?mt=8) to work on getting Game Center integrated. With the docs, the blog post and the code posted in the Game Center tutorial forum thread, I thought I was doing really well.
In fact, now, after it authorizes you, I save your alias and playerID for later reference by calling loadLocalPlayer…
On my new high scores screen, not only do I give the players a button to get to the GameCenter leader board code, but I’m showing the top 5 scores on the page. Using the playerID I saved earlier, I’m bolding any scores that are yours.
So all is good, but I was having my frustrating moments, which is why I’m writing this.
event.errorCode is only set if there are errors. The documentation is clear on this, but I was writing:
if event.errorCode == false then
native.showAlert("Success", json.encode(event.data), { "Ok"})
else
native.showAlert("Error", event.errorMessage, { "Ok"})
end
This will not work. I like writing positive code, in that to me, the if block should contain the success code and the else block the error code.
In other words I would like to write:
if event.errorCode == false then
-- do my sucdess code
end -- because I don't care about the failure
But you can’t do this. You either end up writing a negative oriented block:
if event.errorCode then
-- do your error handling
else
-- do your success stuff
end
or
if event.errorCode == nil then
-- do your success code
end
It would be really nice for event.errorCode to be set regardless or give us a positive way of writing the code. I mean I guess I could do:
if event.data then
...
since data doesn’t exist on error.
Minor detail, but it did frustrate me for a while.
Rob [import]uid: 19626 topic_id: 20798 reply_id: 320798[/import]