[Solved]Create a loop to stop at the first available slot...
#1

Imagine i have 50 vehicles spawned, i've defined MAX_VEHICLES as 100.

Then i destroy vehicle IDs 3, 8, 25

So now i have 47 vehicles left, IDs 1-50 with slots 3, 8 and 25 available.

When a vehicle is created, i will set it VehSpawned[vehid] = 1;

So when looping i will need to find the first available slot, which will be VehSpawned[vehid] == 0

If im looping But how would i create a loop that will stop when it finds the first available slot?

Instead of looping through 100 slots...

Reply
#2

Use break;

Exemple:
pawn Код:
new id;
   
for (id = 1; id < MAX_VEHICLES; id ++)
  if (!VehSpawned[id])
    break;

printf("%d", id);
Reply
#3

Or use 'foreach' and I think 'Itter_Free', whatever it's called it finds the first empty slot in the itterator but this would mean removing the value when you delete a vehicle so it is an empty slot.
Reply
#4

Thanks guys for the replies

Great help
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)