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)

Popular Prag Prog topics Top

kuroneko
Whilst the author has been careful to provide exact results for the tests elsewhere in the book (such as surds with the transformation te...
New
brianokken
Many tasks_proj/tests directories exist in chapters 2, 3, 5 that have tests that use the custom markers smoke and get, which are not decl...
New
jamis
The following is cross-posted from the original Ray Tracer Challenge forum, from a post by garfieldnate. I’m cross-posting it so that the...
New
sdmoralesma
Title: Web Development with Clojure, Third Edition - migrations/create not working: p159 When I execute the command: user=&gt; (create-...
New
jdufour
Hello! On page xix of the preface, it says there is a community forum "… for help if your’re stuck on one of the exercises in this book… ...
New
joepstender
The generated iex result below should list products instead of product for the metadata. (page 67) iex&gt; product = %Product{} %Pento....
New
digitalbias
Title: Build a Weather Station with Elixir and Nerves: Problem connecting to Postgres with Grafana on (page 64) If you follow the defau...
New
brunogirin
When I run the coverage example to report on missing lines, I get: pytest --cov=cards --report=term-missing ch7 ERROR: usage: pytest [op...
New
akraut
The markup used to display the uploaded image results in a Phoenix.LiveView.HTMLTokenizer.ParseError error. lib/pento_web/live/product_l...
New
dachristenson
I’ve got to the end of Ch. 11, and the app runs, with all tabs displaying what they should – at first. After switching around between St...
New

Other popular topics Top

Devtalk
Reading something? Working on something? Planning something? Changing jobs even!? If you’re up for sharing, please let us know what you’...
1016 16836 371
New
AstonJ
We have a thread about the keyboards we have, but what about nice keyboards we come across that we want? If you have seen any that look n...
New
AstonJ
I’ve been hearing quite a lot of comments relating to the sound of a keyboard, with one of the most desirable of these called ‘thock’, he...
New
foxtrottwist
Here’s our thread for the Keyboardio Atreus. It is a mechanical keyboard based on and a slight update of the original Atreus (Keyboardio ...
New
AstonJ
Just done a fresh install of macOS Big Sur and on installing Erlang I am getting: asdf install erlang 23.1.2 Configure failed. checking ...
New
Margaret
Hello content creators! Happy new year. What tech topics do you think will be the focus of 2021? My vote for one topic is ethics in tech...
New
PragmaticBookshelf
Author Spotlight James Stanier @jstanier James Stanier, author of Effective Remote Work , discusses how to rethink the office as we e...
New
PragmaticBookshelf
Rails 7 completely redefines what it means to produce fantastic user experiences and provides a way to achieve all the benefits of single...
New
PragmaticBookshelf
Build efficient applications that exploit the unique benefits of a pure functional language, learning from an engineer who uses Haskell t...
New
PragmaticBookshelf
Author Spotlight: VM Brasseur @vmbrasseur We have a treat for you today! We turn the spotlight onto Open Source as we sit down with V...
New

Latest in PragProg

View all threads ❯