SA-MP Forums Archive
Faster alternative to format()? - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Faster alternative to format()? (/showthread.php?tid=409645)



Faster alternative to format()? - MP2 - 22.01.2013

Is there one? Using format() in a 2000 iteration vehicle loop makes the loop take about 5 seconds! Without it it takes mere miliseconds :/

Even filling the function with tonnes of functions (GetVehiclePos + IsPlayerInRangeOfPoint etc.) doesn't slow it down really at all, but format is taking the piss..


Re: Faster alternative to format()? - ikey07 - 22.01.2013

Do you really need to use format for each car in less then second?

And what you want to formate, try to narrow, like use formate only for Streamed in cars or for cars in 0 Interior or so, just to avoid from blank loop with 2k format();


Re: Faster alternative to format()? - MP2 - 22.01.2013

I was just messing about, I don't need it tbh. I was just wondering A. why it's so slow and B. if there's a faster alternative.


Re: Faster alternative to format()? - ikey07 - 22.01.2013

Need to improvise.
like you can do

new PlayerInEvent[MAX_PLAYERS];

In some event command
Loop for i
if(IsPlayerInEventCar(i,car)) { PlayerInEvent[i] = 1; }


Later elsewhere

Loop for i
if(PlayerInEvent[i] == 1) { SendClient(i,-1," you are in event"); }


or


new PlayerInEvent[10]; //As not whole server can be in the same event aka arena orso.

In some event command
Loop for i
if(IsPlayerInEventCar(i,car)) { Loop for B PlayerInEvent[b] = i; }


Later elsewhere

Loop for i
SendClient(PlayerInEvent[i],-1," you are in event");


Hope you got what I mean, like make slots for certain things, not always you have to loop through all cars or players, or like some faction cars can load apples example, you dont need to use Apples[MAX_VEHICLES]; but just Apples[Faction cars count];


Re: Faster alternative to format()? - MP2 - 22.01.2013

I use foreach. I don't WANT to do format for 2000 vehicles. I did it as a TEST. I want to know if there are alternatives that DON'T LAG.


Re: Faster alternative to format()? - FUNExtreme - 22.01.2013

Go with strcat


AW: Re: Faster alternative to format()? - Kwashiorkor - 22.01.2013

Quote:
Originally Posted by FUNExtreme
Посмотреть сообщение
Go with strcat
strcat does not support arguments - he wants to fill the string with information like position


Re: AW: Re: Faster alternative to format()? - FUNExtreme - 22.01.2013

Quote:
Originally Posted by Kwashiorkor
Посмотреть сообщение
strcat does not support arguments - he wants to fill the string with information like position
That's the problem with not being open minded. It's pretty easy to make strcat work exactly like format, the code is just longer.


AW: Faster alternative to format()? - Kwashiorkor - 22.01.2013

strcat concatenates two strings - might you post an example to use it with floats or integers?


Re: AW: Faster alternative to format()? - FUNExtreme - 22.01.2013

Quote:
Originally Posted by Kwashiorkor
Посмотреть сообщение
strcat concatenates two strings - might you post an example to use it with floats or integers?
You simply use valstr.