String on DIALOG_STYLE_LIST
#1

Hey,

Just saying, that I am a beginner at scripting, so I still don't know many things.

I already made the player count system when a player joins, it increases the count of his job workers. How to make the count of players in each job appear in the DIALOG_STYLE_LIST?

I tried to do like that, but I get warning that number of arguments doesn't match definition and it doesn't work.

Код:
	if (strcmp("/kviesti", cmdtext, true, 8) == 0)
	{
		new string[5];
		format(string, sizeof(string), "%s", taksiConnected);
		format(string, sizeof(string), "%s", mechanikaiConnected);
		format(string, sizeof(string), "%s", policijaConnected);
		format(string, sizeof(string), "%s", narkoConnected);
		format(string, sizeof(string), "%s", medikaiConnected);
		
		ShowPlayerDialog(playerid, 202, DIALOG_STYLE_LIST,"Kviesti tarnyba", "Taksi [%s]\nMedikai [%s]\nPolicija [%s]\nMechanikai [%s]\nNarkotiku prekeiviai [%s]", string, "Pasirinkti", "Atsaukti");
		return 1;
	}
Reply
#2

Код:
if (strcmp("/kviesti", cmdtext, true, 8) == 0)
	{
		new string[125];
		format(string, sizeof(string), "Taksi: %s", taksiConnected);
		format(string, sizeof(string), "Mechanikai: %s", mechanikaiConnected);
		format(string, sizeof(string), "Policija: %s", policijaConnected);
		format(string, sizeof(string), "Narko: %s", narkoConnected);
		format(string, sizeof(string), "Medikai: %s", medikaiConnected);
		
		ShowPlayerDialog(playerid, 202, DIALOG_STYLE_LIST, string , "Pasirinkti", "Atsaukti");
		return 1;
	}
Your cell size for string was too small. Also, The way you wrote it, it doesn't work like that. You added an extra arguement in ShowPlayerDialog function. The previous words which were in your dialog is supposed to be written in formatted function itself.


Edit: Ok ok my bad xD
Reply
#3

Quote:
Originally Posted by Ritzy
Посмотреть сообщение
Код:
if (strcmp("/kviesti", cmdtext, true, 8) == 0)
	{
		new string[125];
		format(string, sizeof(string), "Taksi: %s", taksiConnected);
		format(string, sizeof(string), "Mechanikai: %s", mechanikaiConnected);
		format(string, sizeof(string), "Policija: %s", policijaConnected);
		format(string, sizeof(string), "Narko: %s", narkoConnected);
		format(string, sizeof(string), "Medikai: %s", medikaiConnected);
		
		ShowPlayerDialog(playerid, 202, DIALOG_STYLE_LIST, string , "Pasirinkti", "Atsaukti");
		return 1;
	}
Your cell size for string was too small. Also, The way you wrote it, it doesn't work like that. You added an extra arguement in ShowPlayerDialog function. The previous words which were in your dialog is supposed to be written in formatted function itself.
Well then, how to write those previous words in formatted function?
Reply
#4

I did them.
Reply
#5

@Ritzy - You've forgotten to add a new line on each string "/n".

EDIT: Also, the string you have just formatted is attached to the dialog title, not the content.
Reply
#6

Quote:
Originally Posted by Stev
Посмотреть сообщение
@Ritzy - You've forgotten to add a new line on each string "/n".

EDIT: Also, the string you have just formatted is attached to the dialog title, not the content.
Yes, I was going to ask why is it like that.

But still, even if I added "\n", it only shows me the first line.

Reply
#7

Код:
format(string, sizeof(string), "%sMechanikai: %s\n", string, mechanikaiConnected);
and so on.
Reply
#8

Quote:
Originally Posted by Ritzy
Посмотреть сообщение
Код:
if (strcmp("/kviesti", cmdtext, true, 8) == 0)
	{
		new string[125];
		format(string, sizeof(string), "Taksi: %s", taksiConnected);
		format(string, sizeof(string), "Mechanikai: %s", mechanikaiConnected);
		format(string, sizeof(string), "Policija: %s", policijaConnected);
		format(string, sizeof(string), "Narko: %s", narkoConnected);
		format(string, sizeof(string), "Medikai: %s", medikaiConnected);
		
		ShowPlayerDialog(playerid, 202, DIALOG_STYLE_LIST, string , "Pasirinkti", "Atsaukti");
		return 1;
	}
Your cell size for string was too small. Also, The way you wrote it, it doesn't work like that. You added an extra arguement in ShowPlayerDialog function. The previous words which were in your dialog is supposed to be written in formatted function itself.
I guess you were asleep when you did this code.

Have a close look, what happens to the string, every time you format it? Yes, you overwrite it.


To the thread starter:
Look at the code. You tell the code to "format" a variable called "string". Imagine that string is a box with information. When you do "format(string, sizeof(string), "....", "..."); - you always place new information into it.

You can either use many different string variables and save it to them like this:
PHP код:
new string[30], string2[30]; //This defines a new Array. it also explains [30]: it will be 29 characters long. (not 30)
//do the same for all the variables you need. Variables without [] is normal vars. They can contain a value, such as a number.
format(stringsizeof(string), "Taksi: %s"taksiConnected);
format(string2sizeof(string2), "Mechanikai: %s"mechanikaiConnected);
format(string3sizeof(string3), "Policija: %s"policijaConnected);
format(string4sizeof(string4), "Narko: %s"narkoConnected);
format(string5sizeof(string5), "Medikai: %s"medikaiConnected); 
Then you have saved information to 5 different arrays, right? (They are actually called Arrays, not boxes, remember that)

OR you can use a function called "strcat" in order to place text to the end of an already formatted string.


Let's continue:

PHP код:
ShowPlayerDialog(playerid202DIALOG_STYLE_LIST,"Kviesti tarnyba""Taksi [%s]\nMedikai [%s]\nPolicija [%s]\nMechanikai [%s]\nNarkotiku prekeiviai [%s]"string"Pasirinkti""Atsaukti"); 
This is not right either, because what you do here - should be done in a "format". Only format understands %s and %d (of course with some exceptions).

I would try the following code:
PHP код:
new ResultString[170];
format(ResultStringsizeof(ResultString), "Taksi [%s]\nMedikai [%s]\nPolicija [%s]\nMechanikai [%s]\nNarkotiku prekeiviai [%s]"stringstring5string3string2string4);
//then show the dialog:
ShowPlayerDialog(playerid202DIALOG_STYLE_LIST"TITLE HERE"ResultString"Pasirinkti""Atsaukti"); 
Reply
#9

Quote:
Originally Posted by denNorske
Посмотреть сообщение
I guess you were asleep when you did this code.

Have a close look, what happens to the string, every time you format it? Yes, you overwrite it.


To the thread starter:
Look at the code. You tell the code to "format" a variable called "string". Imagine that string is a box with information. When you do "format(string, sizeof(string), "....", "..."); - you always place new information into it.

You can either use many different string variables and save it to them like this:
PHP код:
new string[30], string2[30]; //This defines a new Array. it also explains [30]: it will be 29 characters long. (not 30)
//do the same for all the variables you need. Variables without [] is normal vars. They can contain a value, such as a number.
format(stringsizeof(string), "Taksi: %s"taksiConnected);
format(string2sizeof(string2), "Mechanikai: %s"mechanikaiConnected);
format(string3sizeof(string3), "Policija: %s"policijaConnected);
format(string4sizeof(string4), "Narko: %s"narkoConnected);
format(string5sizeof(string5), "Medikai: %s"medikaiConnected); 
Then you have saved information to 5 different arrays, right? (They are actually called Arrays, not boxes, remember that)

OR you can use a function called "strcat" in order to place text to the end of an already formatted string.


Let's continue:

PHP код:
ShowPlayerDialog(playerid202DIALOG_STYLE_LIST,"Kviesti tarnyba""Taksi [%s]\nMedikai [%s]\nPolicija [%s]\nMechanikai [%s]\nNarkotiku prekeiviai [%s]"string"Pasirinkti""Atsaukti"); 
This is not right either, because what you do here - should be done in a "format". Only format understands %s and %d (of course with some exceptions).

I would try the following code:
PHP код:
new ResultString[170];
format(ResultStringsizeof(ResultString), "Taksi [%s]\nMedikai [%s]\nPolicija [%s]\nMechanikai [%s]\nNarkotiku prekeiviai [%s]"stringstring5string3string2string4);
//then show the dialog:
ShowPlayerDialog(playerid202DIALOG_STYLE_LIST"TITLE HERE"ResultString"Pasirinkti""Atsaukti"); 
Thank you for the code and detail explanations about those basics.

Unfortunately, the strings that I've made (medikaiConnected, policijaConnected....) don't work. But thank you anyway
Reply
#10

It is smart to start on the very basics, and understand those first - that's for sure

Just read tutorials and look at example codes on the forum. There are a few good turotials on ******* too, actually. They help a lot, as there is a guy that always explains what he's doing, and why.

Good luck!
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)