ChatGPT4 tries using objc bindings with Game Center


I asked ChatGPT 4 to use Codea’s objc to authenticate the player inside Codea. Here’s the code it gave me:

AuthenticationHandler = objc.class("AuthenticationHandler")
function AuthenticationHandler:authenticateLocalPlayer()
    -- Obtain GKLocalPlayer from GameKit
    local GKLocalPlayer = objc.GKLocalPlayer:localPlayer()
    -- Define a block to handle authentication response
    local authResponseBlock = objc.block(function(authViewController, error)
        if authViewController then
            -- Present the authentication view controller
            print("Present the authentication view controller")
        elseif GKLocalPlayer:isAuthenticated() then
            print("Player authenticated")
            print("Player not authenticated:", error)
    end, "v@?@") -- v@?@ is the block signature for this block
    -- Set the authenticate handler
local authHandler = AuthenticationHandler()

It doesn’t work because GKLocalPlayer isn’t available from objc. Would it work if it was?

Hi @UberGoober! ChatGPT doesn’t know much about Codea’s objc feature but it’s interesting to see what it came up with. I’m not sure we ever had an objc.block, but I would have to revisit this code to make it use objc properly.

That being said, it does seem to indicate we are currently missing classes such as GKLocalPlayer. I’ll investigate this with @sim. I believe if it was included you would be able to use it for authentication.


@UberGoober Here’s a sneak peek at a sample I’ve been working one. I’ve been developing it using two VSCode Air Code windows, each connected to a separate device (iPhone + iPad) which made it a lot easier to iterate on this project.

This sample uses GameKit to create a match, invite a friend (both devices must have a different Game Center account), and then send messages to the other player.

I had to make some small changes to Objective-C (support for methods returning “const” results, as well as passing raw string arguments to objective-c methods), so my code would not work with the current TestFlight version, but I’ll share it as soon as the updates are in!

This was a really fun proof-of-concept to work on, and could easily be used as a basis for creating turn-based multiplayer games.