Wrong loop result.
#1

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;
}
Reply
#2

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;
}
Reply
#3

That fixed it, thank you so much.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)