Help with break;
#1

Код:
forward song();
public song()
{
	new rand = random(3);
	for(new i = 0; i < MAX_PLAYERS; i++)
	    if(radiop[i] == 1)
		{
 			StopAudioStreamForPlayer(i);
                        switch(rand)
			{
	    		case 0:
   			    {
		 			PlayAudioStreamForPlayer(i, "http://iusmix.altervista.org/Radio/Skrillex_First_of_the_year.mp3");
		 			SendClientMessage(i, COLOR_YELLOW, "*** Brano corrente: Skrillex - First Of The Year.");
		 			varxkill = SetTimer("song", 263000, false);
		 			break;
    			}
		    	case 1:
				{
					PlayAudioStreamForPlayer(i, "http://iusmix.altervista.org/Radio/Skrillex_-_Rock_n_Roll__Will_Take_You_to_the_Mountain_.mp3");
					SendClientMessage(i, COLOR_YELLOW, "*** Brano corrente: Skrillex - Rock n' Roll.");
				    varxkill = SetTimer("song", 270000, false);
					break;
				}
		    	case 2:
				{
			   		 PlayAudioStreamForPlayer(i, "http://iusmix.altervista.org/Radio/Skrillex_-_Right_In.mp3");
			   		 SendClientMessage(i, COLOR_YELLOW, "*** Brano corrente: Skrillex - Right In.");
					 varxkill = SetTimer("song", 183000, false);
					 break;
				}
			}
			SendClientMessage(i, COLOR_YELLOW, "*** Per fermare questo brano digita/stop!");
		}
}
Hello, this script should start a randomized playlist (i put only 3 cases), logically is correct, but the song start only for the ID 0 player, because "break;" does is function for switch and for...
Why break quit the switch and for, and how can i resolve it?

Sorry for my bad english.
Reply
#2

You are using the break-function, that will stop the loop, that's why it only works for ID 0
Just remove all break-functions.
Reply
#3

If i remove break; all the song start consecutively

The first song work, but when start second song do all other cases
Reply
#4

Yes, i noticed, but if i remove break; all the song start consecutively.


Anywhere i fixed putting SetTimerEx instead SetTimer...
Thanks the same
Reply
#5

I don't know why break; is used to here when you are using timers (Correct me if I am wrong)
Removing them would do the thing; as the timer would start and after it finishes, another case will be started
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)