SA-MP Forums Archive
String loop in dialog - 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: String loop in dialog (/showthread.php?tid=395550)



String loop in dialog - DarkPower - 26.11.2012

pawn Код:
new string[512];
for(new model=508;model<471;model++)
{
     format(string, 512, "%s"#orange"%s\n",string,VehicleNames[model-400]);
}
ShowPlayerDialog(playerid, ..., "Header", string, "Buy", "Close");
I tried to loop throught vehicles model ID 508 to 471 and show their names, but it dosen't work :-/


Re: String loop in dialog - you10 - 26.11.2012

This should fix it
pawn Код:
new string[512];
for(new model=508;model<471;model++)
{
     format(string, 512, "%s"#orange"%s\n",string,VehicleNames[model-400]);
}
ShowPlayerDialog(playerid, ..., "Header", string, "Buy", "Close");



Re: String loop in dialog - DarkPower - 26.11.2012

This is the same code


Re: String loop in dialog - AndreT - 26.11.2012

Sort of makes sense that it does not work. What you're doing is starting the loop with model at value 508, then you increment it until it is smaller than 471. But guess what, that can't work.

What you need to do is figure out what the loop should look like, and from the small snippet you posted, you should probably loop from 0 to sizeof(VehicleNames), that will cover all vehicle names. To get the ID of the vehicle, you then have to add 400 to it.

Also, don't use format for strings as large as this, try strcat instead.


Re: String loop in dialog - DarkPower - 26.11.2012

Omg AndreT, thank you i didn't see, I wanted to start with 471 and stop on 508... Now I am ashamed