Do While Loop stops sometimes
#1

Hello English Community,

Iґve a big problem,
I wanna create a random number of cars with a random modelID on a random parkingplace
and im finnish but my problem is sometimes the do while loop crashes here is my Code:


Код:
	printf("\n\n\n\n\n\nStart");
	rnd = random(sizeof RandomCarPositions);
	new ZiviAuto;
	new Parkplatz;
	new belegt[sizeof RandomCarPositions];
	printf("Anzahl Autos: %d",rnd);
	for(new i = 0;i < rnd; i++)
	{
		do{	
		ZiviAuto = random(sizeof ZiviCars);
		Parkplatz = random(sizeof RandomCarPositions);
		printf("Schleifen durchlauf %d",i);
		fehler = false;
		printf("Start Sekundдrschleife");
		for(new y = 0; y < i;y++)
		{
			printf("Prьfzahl %d",y);//prints y, y loops on time less than x
			if(Parkplatz == belegt[y])//is is a parkingplace in use
			{
				fehler = true;//mistake is 1
				printf("fehler: %d %d",Parkplatz, belegt[y]);//prints to check if its a mistake
				break;
			}
		}
		printf("SekundдrSchleife Fertig fehler: %d",fehler);//finish the secondary loop and prints mistake
		}while(fehler);//if  a mistake again please :)
		printf("%d %f %f %f %f",ZiviCars[ZiviAuto],RandomCarPositions[Parkplatz][car_x],RandomCarPositions[Parkplatz][car_y],RandomCarPositions[Parkplatz][car_z],RandomCarPositions[rnd2][car_a]);//prints every car before creating
		CreateVehicle(ZiviCars[ZiviAuto],RandomCarPositions[Parkplatz][car_x],RandomCarPositions[Parkplatz][car_y],RandomCarPositions[Parkplatz][car_z],RandomCarPositions[rnd2][car_a] + random(0) * 180,random(128),random(128),-1);
		printf("Auto %d Erstellt",i);// car [number] created
		belegt[i] = Parkplatz;
	}
	printf("PrimдrSchleife Fertig!");// end of creation
And this is should printed:
Start
[17:05:31] Anzahl Autos: 3 //Number of cars
[17:05:31] Schleifen durchlauf 0 //Loop number
[17:05:31] Start Sekundдrschleife //Start Loop
[17:05:31] SekundдrSchleife Fertig 0 //finish loop mistake = 0
[17:05:31] 400 2792.743164 -1875.301513 9.555800 179.667602 //the car is created
[17:05:31] Auto 0 Erstellt // its working
[17:05:31] Schleifen durchlauf 1 //everything here again Number of cars is 3 so its looping 3 times
[17:05:31] Start Sekundдrschleife
[17:05:31] Prьfzahl 0
[17:05:31] SekundдrSchleife Fertig 0
[17:05:31] 401 2782.895751 -1875.850585 9.516599 179.667602
[17:05:31] Auto 1 Erstellt
[17:05:31] Schleifen durchlauf 2
[17:05:31] Start Sekundдrschleife
[17:05:31] Prьfzahl 0
[17:05:31] Prьfzahl 1
[17:05:31] SekundдrSchleife Fertig 0
[17:05:31] 405 2797.901611 -1876.006103 9.575400 179.667602
[17:05:31] Auto 2 Erstellt
[17:05:31] PrimдrSchleife Fertig!//finish creation

but this is just sometimes

very often this is printed:

Start
[16:59:46] Anzahl Autos: 0 // No car to create
[16:59:46] PrimдrSchleife Fertig!//finish creation

And here comes the problem:

Start
[16:59:57] Anzahl Autos: 4 //Number of cars 4
[16:59:57] Schleifen durchlauf 0 // Loop 0
[16:59:57] Start Sekundдrschleife Start second loop (the loop in the while)
[16:59:57] SekundдrSchleife Fertig 0 //finish mistake is 0 so it goes out of the While LOOP
AND HERE THE LOOP CRASHES No car create, no more print.

Can anyone explain me whe the while loop crashes ?

Sorrys for my mistakes and the german code im from the german SA:MP Community
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)