Wrong loop result. - 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: Wrong loop result. (
/showthread.php?tid=628633)
Wrong loop result. -
Rongvaldyr - 12.02.2017
Hello, I'm trying to make a dialog command to show which businesses are accepting cargo
So this is my code, there is 2 businesses accepting cargo but it only shows one
Anyone know how to fix this?
Code:
CMD:test1(playerid, params[])
{
new count = 0;
new string[512];
for(new i; i < MAX_PLAYERS; i++)
{
if(bInfo[i][bPI] == 1)
{
format(string, sizeof(string), "%s %d %d\n", bInfo[i][bName], bInfo[i][bPW], bInfo[i][bPM]);
count++;
}
}
Dialog_Show(playerid, KKE, DIALOG_STYLE_LIST, "TEST", string, "TEST", "TEST");
if(count == 0)
{
SendMSG(playerid,"No one accepting product.");
}
return 1;
}
Re: Wrong loop result. -
jlalt - 12.02.2017
You're formatting the string every time it finds a biz so only last found biz will be inside the string.
Fix: put the string inside it self when formating.
Code:
CMD:test1(playerid, params[])
{
new count = 0;
new string[512];
for(new i; i < MAX_PLAYERS; i++)
{
if(bInfo[i][bPI] == 1)
{
format(string, sizeof(string), "%s%s %d %d\n", string, bInfo[i][bName], bInfo[i][bPW], bInfo[i][bPM]);
count++;
}
}
Dialog_Show(playerid, KKE, DIALOG_STYLE_LIST, "TEST", string, "TEST", "TEST");
if(count == 0)
{
SendMSG(playerid,"No one accepting product.");
}
return 1;
}
Re: Wrong loop result. -
Rongvaldyr - 12.02.2017
That fixed it, thank you so much.