mikecargal

mikecargal

Apple Game Frameworks and Technologies: currentPlayer = nil

Title: Apple Game Frameworks and Technologies: currentPlayer = nil (page 412)

Given my recent track record on my problem posts, I would not blame anyone for giving me a day or so to discover what I did wrong.

In this case. in the canTakeTurn() func called from GameScene.setupRemoteGame(), the match.currentParticipant?.player is nil. Both instances are getting the same nil result, so both instances think it’s the other player’s turn. So far, I’m not seeing a way to reset things, but I would think that, if it’s possible that the match.currentParticipant?.player can be nil, then there should be some code to handle that state. (BTW, the match.currentParticipant is not nil. Here’s a bit of print output attempting to debug this:

Attempting to load the lobby scene.
player( <GKLocalPlayer: 0x600001aa6100>(alias:App Tester 2 name:App Tester 2 status:(null) friendBiDirectional:0 friendPlayedWith:0 friendPlayedNearby:0 acceptedGameInviteFromThisFriend:0 initiatedGameInviteToThisFriend:0 automatchedTogether:0)
 receivedTurnEventFor:<GKTurnBasedMatch 0x600003a716e0 - matchID:2dc64251-a2ed-4d8b-a3cf-6e43530492eb bundleID:com.mikecargal.hogdice status:GKTurnBasedMatchStatusMatching message:'' creationDate:2021-01-26 15:43:22 +0000 currentParticipant:<GKTurnBasedParticipant 0x6000036be7b0 - status:Matching matchOutcome:None lastTurnDate:(null) timeoutDate:(null)> participants:<GKTurnBasedParticipant 0x6000036be9d0 - status:Active matchOutcome:None lastTurnDate:2021-01-26 15:45:48 +0000 timeoutDate:(null)>,<GKTurnBasedParticipant 0x6000036be7b0 - status:Matching matchOutcome:None lastTurnDate:(null) timeoutDate:(null)> matchData.length:151 matchDataMaximumSize:65536 exchanges:(null) state:4>
didBecomeActive:true
 -- currentplayer: nil
Attempting to load the game scene using Game Center Match data.
Attempting to load the game scene.

for context this is where most of this output comes from:

   func player(_ player: GKPlayer,
                receivedTurnEventFor match: GKTurnBasedMatch,
                didBecomeActive: Bool)
    {
        print("player( \(player)\n receivedTurnEventFor:\(match)\ndidBecomeActive:\(didBecomeActive)")
        print(" -- currentplayer: \(match.currentParticipant?.player)")
        matchmakerViewController?.dismiss(animated: true, completion: nil)
        NotificationCenter.default.post(name: .receivedTurnEvent, object: match)
    }

    func canTakeTurn() -> Bool {
        guard let match = currentMatch else { return false }
        let currentParticipant = match.currentParticipant
        let currentPlayer = currentParticipant?.player
        print("match = \(match)\ncurrentPlayer = \(currentPlayer)\nlocalPlayer = \(GKLocalPlayer.local)")
        return match.currentParticipant?.player == GKLocalPlayer.local
    }

Going to take the challenge of trying to sort out how to handle this state, but thought I’d pass along…

BTW… an observation: In Chapter 17, the instructions generally go along the lines of “replace // TODO: …” with … That works OK on the first pass, but makes going back through to double check your work a bit challenging.

observation 2: The instructions to respond to certain events by posting a notification and then responding to that notification over in another class, could use a bit of elaboration as to why that’s the thing to do. It’s not clear if it’s just demonstrating another way of getting something done in another class, or if there’s some sort of reason why the “real work” needs to happen on the thread that the Observer is running on (just a wild guess as to what might be behind that)

First Post!

mikecargal

mikecargal

I’m not quite to the bottom of things yet, but I have observed something that, I think, throws a kink in the book’s logic.

When I set up my tester account, apple assigned a name of “Player_4939364543”, I didn’t really like that, so I worked to change it to “App Tester 2” on my simulator. When I get into the addPlayer() function, I’ve received “App Tester 2” from the loadGameCenterGame() function, but already have “Player_4939364543” loaded.

As you can see from the debugging variables, both the existing players[0] and the player I’m adding have a player ID of “A:_d1bd1278a67fdab60ac1de3fc6089d18”, but have different names. I would take that to mean that the playerId (alone) uniquely identifies the player, and that trying to look the player up by name is misguided.

I’m not positive, but suspect that this will be a factor in tracking down this behavior.

I hate to keep dragging folks through troubleshooting my typos, but in this case, I’m pretty sure that this is a real-world scenario that the code in the book should handle correctly. (people are going to be able to rename their players (which apparently gives them a different name locally (??? - really foggy on this so far)))

Popular Prag Prog topics Top

iPaul
page 37 ANTLRInputStream input = new ANTLRInputStream(is); as of ANTLR 4 .8 should be: CharStream stream = CharStreams.fromStream(i...
New
Alexandr
Hi everyone! There is an error on the page 71 in the book “Programming machine learning from coding to depp learning” P. Perrotta. You c...
New
edruder
I thought that there might be interest in using the book with Rails 6.1 and Ruby 2.7.2. I’ll note what I needed to do differently here. ...
New
raul
Page 28: It implements io.ReaderAt on the store type. Sorry if it’s a dumb question but was the io.ReaderAt supposed to be io.ReadAt? ...
New
alanq
This isn’t directly about the book contents so maybe not the right forum…but in some of the code apps (e.g. turbo/06) it sends a TURBO_ST...
New
rmurray10127
Title: Intuitive Python: docker run… denied error (page 2) Attempted to run the docker command in both CLI and Powershell PS C:\Users\r...
New
curtosis
Running mix deps.get in the sensor_hub directory fails with the following error: ** (Mix) No SSH public keys found in ~/.ssh. An ssh aut...
New
adamwoolhether
I’m not quite sure what’s going on here, but I’m unable to have to containers successfully complete the Readiness/Liveness checks. I’m im...
New
creminology
Skimming ahead, much of the following is explained in Chapter 3, but new readers (like me!) will hit a roadblock in Chapter 2 with their ...
New
bjnord
Hello @herbert ! Trying to get the very first “Hello, Bracket Terminal!" example to run (p. 53). I develop on an Amazon EC2 instance runn...
New

Other popular topics Top

Exadra37
Please tell us what is your preferred monitor setup for programming(not gaming) and why you have chosen it. Does your monitor have eye p...
New
Exadra37
On modern versions of macOS, you simply can’t power on your computer, launch a text editor or eBook reader, and write or read, without a ...
New
New
dimitarvp
Small essay with thoughts on macOS vs. Linux: I know @Exadra37 is just waiting around the corner to scream at me “I TOLD YOU SO!!!” but I...
New
PragmaticBookshelf
Learn different ways of writing concurrent code in Elixir and increase your application's performance, without sacrificing scalability or...
New
wmnnd
Here’s the story how one of the world’s first production deployments of LiveView came to be - and how trying to improve it almost caused ...
New
New
New
PragmaticBookshelf
Author Spotlight: Peter Ullrich @PJUllrich Data is at the core of every business, but it is useless if nobody can access and analyze ...
New
AstonJ
This is a very quick guide, you just need to: Download LM Studio: https://lmstudio.ai/ Click on search Type DeepSeek, then select the o...
New

Latest in PragProg

View all threads ❯