Help with millis() in a loop

Hi everybody, I need your help please! :cold_sweat:

first of all hereĀ“s the code:

void loop(){
getnewgame();
delete_melody();
while (gameon == true){
melody_length = add_tone();
play_melody();
active_player = 0;
for (int pos = 0; pos < melody_length; pos++){
unsigned long time = millis();
while(millis()- time < zug_zeit && active_player == 0){
if (digitalRead(pl1_pin) == LOW){active_player = 1;}
if (digitalRead(pl2_pin) == LOW){active_player = 2;}
if (digitalRead(pl3_pin) == LOW){active_player = 3;}
if (digitalRead(pl4_pin) == LOW){active_player = 4;}
Serial.println(millis()-time);
}

if (millis() - time > zug_zeit){
kill(melody[pos]);
gameon = false;
break;
}
else if (active_player != melody[pos]){
kill(active_player);
gameon = false;
break;
}
else {play(melody[pos]);}
active_player = 0;

}
play_all();
delay(200);
}
}

You can see the Serial.println(millis()-time); that prints out the time difference. I dontĀ“t really need this function in my program, nor do I need any Seral communication, this was just for debugging BUT: The funny thing is, when the time runs out,
if (millis() - time > zug_zeit){
kill(melody[pos]);
gameon = false;
break;
}

condition is not called unless i put the Serial.println command in the while loop.
Can anybody explain why?

Thanks a lot guys this is killing me!

time, goes out of Scope since it was declared in the for loop.
Move the "unsigned int time" out of the for loop.

embarassing XD

sometimes it s really simple. thanks a lot !

seems like its time for a break