Daily Learning Notes for July 6th, 2017

Today was a short day, since I just took care of some admin stuff, did a little work on the mob coding app, chatted with friends, accidentally slept away the entire afternoon, and then I went out with a group to see the new “Spiderman” movie.

Real-time notes:

11:22am: After a quick meditation and getting ready (and trying to fix up my crazy curly hair), I spent the whole morning taking care of emails and event planning stuff and reading about the entertainment tech hackathon happening this weekend. Not sure if I want to go, but it is free to attend! I’m feeling very indecisive right now, with lots of pending decisions and lots of new ideas from yesterday. I’m still excited about all the possibilities, but I also feel a bit frustrated because I don’t know how to choose just one thing! I guess I’ll just chip away at my mob coding app some more, since I already have some momentum there and I never got to finish fixing that timer bug from yesterday. First I’ll take a quick break though; I’ve been sitting still for too long!

11:39am: I feel like doing a few math problems on Khan Academy first while I try to wake up with a little more coffee.

12:07pm: That was frustrating! I’m still pretty terrible at long division, haha. But that was good to review. OK, back to the mob coding app! Where did I leave off? Oh, it looks like I actually finished implementing that change in my code – I’m using timestamps everywhere! Yay! Maybe I just didn’t get to test it yet. I’ll test it out now. Hmm… Well, it sort of works. But not really. Something is messed up, but I’m not even sure exactly how to identify the problem! Definitely feeling frustrated now. Maybe today is the right day to start learning about redux, haha. It might make it easier to debug this! But I’ll try a bit harder to figure it out. Or maybe it’s time to give in and take a nap soon, I’m not sure. I’ll take another look…

12:17pm: Looks like everything breaks when the turn timer goes off! Let’s see what the clients are doing when the turn changes… Oh, looks like I forgot to actually update the timestamp! Maybe this is an easy fix after all. I’ll just hard-code the turn duration on the client-side as well. Good enough for now! Let’s test it again! OK, something weird is still happening with the timer on the clients… Oh, I forgot that I need to add the turn duration to the current timestamp. Oops! Let’s try this again.

12:29pm: Back in business! It’s working! Onto the next bugs: there’s no Gist anymore! What’s cool is the lack of a Gist isn’t generating any errors or breaking anything else, so that’s a good sign that I’ve organized my code in a nice modular way. Another bug: some error is still being thrown after the current player disconnects, but only sometimes.

12:35pm: Lunch break!

1:28pm: I went for a quick walk, talked to my coworking buddies, ate the rest of the leftover al pastor pork (yummy!), and now I want to try to do a bit more work before I give in and take a nap. Wouldn’t it be great if I fixed these last couple of bugs? (Ah, but I wonder how many more will pop up next!) I’ll focus on this disconnection bug first. When does it happen, and when does it not happen?

Testing for that disconnection bug:

  • Two players join, current player disconnects before first turn ends – all good!

  • As long as the turn change is triggered by the current player disconnecting, all is good!

  • Two players join, first turn ends, then current player disconnects before second turn ends – error!

  • Once the turn has changed due to the timer running out, if the current player disconnects, this triggers the error!

  • After the error has been triggered, if another user joins and the turn changes due to the timer running out again, the error goes away, but then both clients of neither client are the current player! Weird!

The error says Cannot read property 'id' of undefined on the client-side, because the getCurrentPlayer() function is returning undefined when it’s called by the togglePlayerHighlight() function, called by the handleTurnChange() function. Hmm. The current player should never be undefined as long as the game is running, so something is wrong here!

1:48pm: I think it’s just because the turn index is pointing to a slot in the array that no longer exists. When updating any of the UI for the previous player, I should really be checking if the previous player still exists! I should just refactor that togglePlayerHighlight() function. That should fix it – at least partially. I bet React would help with this a lot! I guess I could refactor it even more… also, if the current player disconnects and then the turn changes, and I try to access the data of the previous player on the client, what am I actually accessing? I’ll try using the Chrome debugger this time.

2:10pm: Still messing around with the debugger and looking through my code. I guess I must be sleepy, because I keep losing my train of thought.

Debugging disconnection and turn change state of previous player:

  • Normal turn change:

    • Before client changes the turn: currentPlayer: 0, previousPlayer: 0, turnIndex: 0, players.length: 2

    • After client changes the turn: currentPlayer: 1, previousPlayer: 0, turnIndex: 1, players.length: 2

  • Turn change triggered by current player disconnecting:

    • Before client changes the turn: currentPlayer: 0, previousPlayer: 0, turnIndex: 0, players.length: 1

    • After client changes the turn: currentPlayer: 0, previousPlayer: 0, turnIndex: 1, players.length: 1

Right, so I just wanted confirm it for myself: the logic is basically wrong in the handleTurnChange() function if the turn change was triggered because a user disconnected.

2:21pm: What should I do about this? All the logic is wrong if previousPlayer is actually pointing to the current player! I made a big assumption there, and I got it wrong. Hmm. I’m stuck again. I feel the frustration, amplified by sleepiness. Reminding myself that this is an honorable state to be in! I realized my mistake, and now I can learn from looking at everything else with a fresh perspective as I try to uncover the other implications of my incorrect assumption.

Some of my assmuptions to re-examine:

  • Back when I made that initial state machine diagram for the app (last week on June 30th), I assumed that the only event affecting the actual state of the client would be the turnChange event, but I didn’t look at how the turn change triggers other events in different ways depending on what caused the turn to change!

  • Right now, the handleTurnChange() function takes care of a few different tasks: updating nextTurnTimestamp, changing the turn (updating the local game state), forking/editing the Gist, toggling the editor’s read-only mode, and updating all of the UI. This is probably an overloaded function!

  • Maybe the turnChange event and playerLeft events should be entirely separate, instead of having one trigger the other? Which tasks differ depending on whether both events were triggered or just one?

  • Or maybe I should just add one more condition to the handleTurnChange() function and pass in a variable signaling if a player disconnected, so that way the forking/editing and UI update related to the previous player won’t happen at the wrong time.

2:38pm: This is quite frustrating indeed. The state machine diagram for this app, especially its transitions, are more complicated than I thought! I think I’ll have to scribble some stuff on paper to try to fix this. Well, time to take that nap.

6:11pm: Wow, that was a long nap! From about 3pm to 5:30pm or even more… let’s just call it 3 hours. That might be a new record for me – longest nap in the meditation room here at the coworking space! I feel so strange. My heart is pounding, my head hurts, my eyes feel weird. But I feel awake. I know that once the grogginess wears off, I’ll feel wide awake even if I don’t want to. At least I know I’ll be awake to see that new “Spiderman” movie tonight! I might not be able to sleep tonight though. Oh well. Right now I’m just hanging out upstairs, and looks like I’m going to help put away a bunch of cards for that game Dominion! Then it’ll be time to hop on the Metro soon.

Wrapping up: I liked “Spiderman” and it was fun to have a movie night! I had a bite to eat when I got home, did some dishes, and went to bed. (It took a while to get home after the Metro, picking stuff up from the coworking space, and then walking back.) I did indeed have trouble falling asleep, but it wasn’t too bad.