String on DIALOG_STYLE_LIST -
LI0LIKAS - 22.01.2018
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;
}
Re: String on DIALOG_STYLE_LIST -
Ritzy2K - 22.01.2018
Код:
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
Re: String on DIALOG_STYLE_LIST -
LI0LIKAS - 22.01.2018
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?
Re: String on DIALOG_STYLE_LIST -
Ritzy2K - 22.01.2018
I did them.
Re: String on DIALOG_STYLE_LIST -
Stev - 22.01.2018
@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.
Re: String on DIALOG_STYLE_LIST -
LI0LIKAS - 22.01.2018
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.
Re: String on DIALOG_STYLE_LIST -
Kane - 22.01.2018
Код:
format(string, sizeof(string), "%sMechanikai: %s\n", string, mechanikaiConnected);
and so on.
Re: String on DIALOG_STYLE_LIST -
denNorske - 22.01.2018
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(string, sizeof(string), "Taksi: %s", taksiConnected);
format(string2, sizeof(string2), "Mechanikai: %s", mechanikaiConnected);
format(string3, sizeof(string3), "Policija: %s", policijaConnected);
format(string4, sizeof(string4), "Narko: %s", narkoConnected);
format(string5, sizeof(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(playerid, 202, DIALOG_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(ResultString, sizeof(ResultString), "Taksi [%s]\nMedikai [%s]\nPolicija [%s]\nMechanikai [%s]\nNarkotiku prekeiviai [%s]", string, string5, string3, string2, string4);
//then show the dialog:
ShowPlayerDialog(playerid, 202, DIALOG_STYLE_LIST, "TITLE HERE", ResultString, "Pasirinkti", "Atsaukti");
Re: String on DIALOG_STYLE_LIST -
LI0LIKAS - 22.01.2018
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(string, sizeof(string), "Taksi: %s", taksiConnected);
format(string2, sizeof(string2), "Mechanikai: %s", mechanikaiConnected);
format(string3, sizeof(string3), "Policija: %s", policijaConnected);
format(string4, sizeof(string4), "Narko: %s", narkoConnected);
format(string5, sizeof(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(playerid, 202, DIALOG_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(ResultString, sizeof(ResultString), "Taksi [%s]\nMedikai [%s]\nPolicija [%s]\nMechanikai [%s]\nNarkotiku prekeiviai [%s]", string, string5, string3, string2, string4);
//then show the dialog:
ShowPlayerDialog(playerid, 202, DIALOG_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
Re: String on DIALOG_STYLE_LIST -
denNorske - 22.01.2018
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!