So I have a while loop that is being triggered, and for naming I am using an additional value.
totalPlayerCount can be either 1,2,3 or 4 and whatever I choose for that seems to automatically set nameLoop that value.. regardless of nameLoop = 1;
To top it off, I have nameLoop++; as the bottom and when it starts it says Player 4, then Player 3, then Player 2, then Player 1…
Why on earth would it be going backwards? Theres only 3 instances of nameLoop in the whole file so its not being affected anywhere else.
public void setNames() {
int nameLoop = 1;
while (totalPlayerCount >= 1){
//**********************//
//***SET PLAYER NAMES***//
//**********************//
AlertDialog.Builder alert = new AlertDialog.Builder(this);
alert.setTitle("Player " + nameLoop);
alert.setMessage("Name:");
// Set an EditText view to get user input
final EditText input = new EditText(this);
alert.setView(input);
alert.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
name = input.getText().toString();
// Do something with value!
Toast.makeText(getApplicationContext(), name, Toast.LENGTH_SHORT).show();
}
});
alert.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
// Canceled.
}
});
alert.show();
totalPlayerCount--;
nameLoop++;
}
return;
}
It looks like you are counting down the number of players while iterating through them. Try changing it to:
This should fix it, but the part you really need to change is where ever you are using
nameLoopto assign player number.