I am beyond confused and never had this issue before.
To sum up what I am doing: I am trying to make a card game run on the arduino. Basically, the arduino is used to calculate and keep score of all players. The scores are written into the Serial Monitor. however, I have run into a very odd problem.
The whole code is very messy looking, but I have things in place that allow me to keep track of all of the variables after each loop, so I can make sure they are correct. I'll sum up the code and keep it simple.
For the loop, I have it running side commands that I've created so I can keep the loop section neat and tidy. It looks something like this:
void loop(){
Serial.println("Hey, how many players you want?");
countPlayers(); // grabs number typed into Serial Monitor, and saves it as "int pNumber"
Serial.println("Let's start the next round");
StartRound(); // this loops until the round is over, taking player points typed into the SM
displayScores(); // descriptive enough
resetBids(); // resets bids for next round, because they need to be 0 at the start
setNewDealer(); // Shifts dealer number by 1, but if max player is reached, its set to 0 (starting player)
}
There is another command "debug();" , where this command simply puts a list of variables into the SM, that way I can check where all the variables are in between commands. By placing this debug command in between each command, I can see how the variables change. This is where I noticed something going on.
During the countPlayers command, it takes the SM input and saves a variable pNumber as the max players for that game. This should never change unless the arduino is restarted and a new number is set. However, for whatever reason, during the "resetBids" command, it is resetting the pNumber to 0. Here is the code for the "resetBids" command:
int bet[]={0,0,0,0,0,0,0};
void resetBids() {
for (int x = 0; x < 7; x++) {
bet[x] = 0;
}
}
As you can see, pNumber has NOTHING to do with this command. Another thing is, if I switch the command to look like this:
int bet[]={0,0,0,0,0,0,0};
void resetBids() {
bet[0]=0;
bet[1]=0;
bet[2]=0;
bet[3]=0;
bet[4]=0;
bet[5]=0;
bet[6]=0;
}
The command no longer resets pNumber to 0. Does anyone know what's going on? is this just a random bug that I found and I should just stick with my second setup? my concern is that if I don't fix this, it may cause unforseen problems down the road, since I cannot anticipate every order of moves/bets players will make in one game.
Sorry this is long, I appreciate any help you guys can give!!