SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help

Reply
 
Thread Tools Display Modes
Old 12/02/2017, 02:37 PM   #1
Rongvaldyr
Little Clucker
 
Join Date: Oct 2016
Posts: 12
Reputation: 2
Default Wrong loop result.

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;
}
Rongvaldyr is offline   Reply With Quote
Old 12/02/2017, 02:40 PM   #2
jlalt
Banned
 
Join Date: Oct 2014
Location: Iran
Posts: 1,266
Reputation: 366
Default Re: Wrong loop result.

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;
}
jlalt is offline   Reply With Quote
Old 12/02/2017, 02:51 PM   #3
Rongvaldyr
Little Clucker
 
Join Date: Oct 2016
Posts: 12
Reputation: 2
Default Re: Wrong loop result.

That fixed it, thank you so much.
Rongvaldyr is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Wrong loop result. Rongvaldyr Scripting Help 4 19/01/2017 04:39 AM
Wrong Result PowerF Scripting Help 6 20/09/2015 07:31 AM
Only 1 player will be shown from loop result iPrivate Scripting Help 11 27/10/2014 11:48 PM
[Help] MySQL returning wrong result Maxips2 Scripting Help 6 08/09/2012 10:11 PM
How to stop a for/while loop looping after it founds the first result? DJ-CJ89 Help Archive 4 15/04/2010 11:20 AM


All times are GMT. The time now is 06:00 AM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.