I've got a bug in which the value of an int array slot is being inadvertently changed to a value of 255. I've narrowed down the cause to a function call, which if commented out fixes the issue. The weird thing is, nothing in that function makes any reference to the affected array or calls any other functions that might do so (unless the fastLED library is doing something I can't see).
The array being affected is playerScores, and the function affecting it is waitingPlayerLed() called at line 135. Sorry, the code is too long to embed here; link instead:
I've included 2 serial monitor screenshot attachments of what it should look like versus what actually happens. When operating correctly, a player who holds their RFID tag to the reader is able to earn a point every second for as long as the round time hasn't expired (reflected in serial monitor). Then, it's the other players turn.
In the bug version though, you'll see that at the end of the round, when gameIsLive == 0, playerScore now holds a value of 255. The only code in the entire script that should change any slot in playerScores is a simple playerScores[x]++, so I have no idea why it's jumping to 255.
You wasted a huge amount of resources posting pictures of text. Do not do that again. Post text AS TEXT!
If you had bothered to read the "Read this before posting..." threads, you would know that you will get NO help here unless you POST YOUR CODE.
Read the stickies BEFORE replying, and post your code properly.
Homie, I did review the stickies. The screenshots are from the serial monitor, not my script. The post character limits don't allow me to fit the entire code. Do you want half of it now, and then the functions 5 minutes later? I pre-emptively apologized for not being able to do this from the beginning as a result of the restrictions imposed by the forum itself. I included the link to streamline the process as the next best option.
The screenshots are from the serial monitor, not my script.
Your script sent data to an application that only knows how to display text. You can cut-and-paste the text here.
The post character limits don't allow me to fit the entire code.
If you had read the rules, you'd have learned two things. One would be how to attach the code when it is more than 9500 characters. The other is the need to develop a minimal sketch to illustrate the problem. Often, in doing that, you'll have a face-palm moment, and not need to post at all.
I pre-emptively apologized for not being able to do this from the beginning as a result of the restrictions imposed by the forum itself.
The rules wouldn't be needed if every shit-stain spammer on earth suddenly got annihilated.
This function waits for the correct RFID tag and then activates the round timer for that player. waitingPlayerLed() controls the LED display to display the color of the player whose turn it is.
Isn't that more or less an atomic activity? A player takes a turn, the next player is up, and needs to be shown and his/her turn timer started. Seems like one operation (function call) to me, not two. YMMV.
You can, of course, keep waitingPlayerLed(), but call it from wiatingPlayer().
Without the actual output, it's hard to see what is wrong.
j will be assigned a value of 40, and leds will be written to. There is no leds. The maximum index of the leds array is 39.
I... I think that may have done it! So it seems by telling the fastLED library that I have 40 LEDs, it's creating an index somewhere between 0-39 (for a total count of 40). But by accidentally assigning a rgb value at position 40, it looks like it's actually pointing toward the memory address for the player 1 score! Sure enough, when I throw some dummy values in there, playerScores reflects those same numbers. And by using "<" instead of "<=", it seems to mitigate the issue! I have some familiarity with referencing beyond an array's index, but had no idea how subtle it could be. Thanks so much!
And thank you for persevering through the forum restrictions and our insistence that you follow the rules (guidelines, actually), so that we could actually help you. Thank you, too, for following up once you incorporated the fix.
And, yes, writing outside the bounds of an array can cause all kinds of subtle bugs.