Little request for 'FOR'() -
Micheal_ - 13.07.2011
Hey, someone can make for me a 'for' loop that reads 3 keys from a file, and if their string vaule isn't equal to "empty" its show each one of them in a one dialog box (list)
THANK YOU VERY MUCH!
File read string function:
pawn Код:
item 1: DOF2_GetString(User, "item1", "ITEMS");
item 2: DOF2_GetString(User, "item2", "ITEMS");
item 3: DOF2_GetString(User, "item3", "ITEMS");
Re: Little request for 'FOR'() -
PotH3Ad - 13.07.2011
Try this
pawn Код:
new str[250], key[10]; //might need to increase this, depending on the file value's
for(new x=0; x<=2; x++) //Loop 3 times
{
format(key, sizeof(key), "item%d", x+1); //format the key to read from
if(strlen(DOF2_GetString(User, key, "ITEMS")) > 0) format(str, sizeof(str), "%s%s\n", str, DOF2_GetString(User, key, "ITEMS")); //If the file value isn't empty, format the string with the file value
else continue; //if the file value is empty, continue the loop.
}
Re: Little request for 'FOR'() -
Micheal_ - 13.07.2011
Thank you very much for your help. But I need that to read a three strings like I wrote at my post above.
I mean, in your code you're reading/checking string length of only one key.
I got three keys, to check if they are empty or not, and all the keys that empty won't be shown at the dialog box.
Thank you very much PotH3Ad, keep it up.
Re: Little request for 'FOR'() -
PotH3Ad - 14.07.2011
It's checking the string length of all of them already. Everytime the code inside the loop is called, it formats the string with the formatted key and then it checks the key value.
Re: Little request for 'FOR'() -
Micheal_ - 14.07.2011
So after:
I need to add this?
Quote:
ShowPlayerDialog(playerid, 0, DIALOG_STYLE_LIST, "Items", str, "OK", "Cancel");
|
Because it just won't show the dialog, until I edits 'str' (in ShowPlayerDialog, see above) to "asdasd" (for example) And then it shows the dialog.
What did I do wrong?
Thanks
Re: Little request for 'FOR'() -
PotH3Ad - 14.07.2011
pawn Код:
new str[250], key[10]; //might need to increase this, depending on the file value's
for(new x=0; x<=2; x++) //Loop 3 times
{
format(key, sizeof(key), "item%d", x+1); //format the key to read from
if(strlen(DOF2_GetString(User, key, "ITEMS")) > 0) format(str, sizeof(str), "%s%s\n", str, DOF2_GetString(User, key, "ITEMS")); //If the file value isn't empty, format the string with the file value
else continue; //if the file value is empty, continue the loop.
}
ShowPlayerDialog(playerid, 0, DIALOG_STYLE_LIST, "Items", str, "OK", "Cancel");