Hello there, I was wondering the following:

I recently made a script which used a "for" to link some vehicles to an interior.

It was something like this:

for(new i; i >= 10; i++)
  LinkVehicleToInterior(rVehicles[i], 9);
  SetVehicleVirtualWorld(rVehicles[i], 8);
The thing is that it didn't work. The vehicles didn't link to the damn interior or the virtual world. Desperating.

When I removed the for and did it all like this
LinkVehicleToInterior(rVehicles[0], 9);
LinkVehicleToInterior(rVehicles[1], 9);
LinkVehicleToInterior(rVehicles[2], 9);
LinkVehicleToInterior(rVehicles[3], 9);

Surprisingly it worked. Why does this happen?

for (new i; i >= 10; i++)
This will increment i while it's equal or more than 10 so it never gets incremented.
It has to be like this
for (new i; i <= 10; i++)

Because your loop condition is wrong. It is checking if i is greater than or equal to 10 but since i is initialized to zero it never is. Thus the loop never runs. Also use sizeof instead of statically typed limits. Sizeof is an operator and has no impact on runtime performance.

Aw, good to know lmao

Thanks + rep

Yeah i did use sizeof but just not to put it in the sample code

Forum Jump:

Users browsing this thread: 1 Guest(s)