Save a value in a Dialog [+REP] -
Amit1998 - 20.05.2016
Hey guys,
I'm trying to make a list(dialog) which displays variable logs. Each log is marked by an SqlID(meaning they're not sorted by 0..1..2..3.., they might be sorted as 3..5..11.93..).
How can I save the SqlID in order to use it in a sub dialog?
I'll try to demonstrate it
__ DIALOG __
ID: 2 | By: Forum_SAMP | Date 22/11/00
ID: 8 | By: Forum_SAMP | Date 22/11/00
ID: 12 | By: Forum_SAMP | Date 22/11/00
ID: 23 | By: Forum_SAMP | Date 22/11/00
When I click on one of these, it looks for the row(by the ID) in a table(mysql) and opens up a dialog msg box with information about this log. However, I dont manage to save up the ID for furthur use. Any tips?
+REPing the helpers
Re: Save a value in a Dialog [+REP] -
Nero_3D - 20.05.2016
Use sscanf on
inputtext[] - The text entered into the input box by the player or
the selected list item text.
to extract your id
Re: Save a value in a Dialog [+REP] -
Amit1998 - 20.05.2016
Quote:
Originally Posted by Nero_3D
Use sscanf on
inputtext[] - The text entered into the input box by the player or the selected list item text.
to extract your id
|
Humm.. assuming the string is:
Lottery ID: 3 | Started By: Forum_Samp | Date: 11/22/33
Lottery ID: 492 | Started By: Forum_Samp | Date: 11/22/33
How can I make it extract the ID of the lottery?
Re: Save a value in a Dialog [+REP] -
Konstantinos - 20.05.2016
pawn Код:
new extracted_ID;
sscanf(inputtext, "'Lottery ID:'i{s[128]}", extracted_ID);
printf("Lottery ID: \"%i\"", extracted_ID);
Re: Save a value in a Dialog [+REP] -
Stinged - 20.05.2016
Код:
new str[5], id;
new string[58] = "Lottery ID: 492 | Started By: Forum_Samp | Date: 11/22/33";
new pos = strfind(string, " |");
strmid(str, string, 12, pos);
id = strval(str);
printf("ID: %i", id);
Here's an example of doing it using the native string functions.
EDIT: Konstantinos already posted, didn't refresh the page.
I'm not sure if there's a huge speed difference to be honest.
(I know sscanf is going to be faster, I don't know by how much though)
EDIT 2: The difference really started showing when it ran more than 10000000 times.
Re: Save a value in a Dialog [+REP] -
Amit1998 - 20.05.2016
Quote:
Originally Posted by Konstantinos
pawn Код:
new extracted_ID; sscanf(inputtext, "'Lottery ID:'i{s[128]}", extracted_ID); printf("Lottery ID: \"%i\"", extracted_ID);
|
Humm, here's what I used on the DialogResponse callback:
PHP код:
new extracted_ID[4];
sscanf(inputtext, "'LotteryID:'i{s[128]}", extracted_ID);
new zz = strval(extracted_ID);
mysql_format(MySQLPipeline, iQuery, sizeof(iQuery), "SELECT * FROM `lotteries` WHERE `ID` = '%d'", zz);
printf("ID: %i", zz);
tho it prints out ID: 0 and no logs are found.
What could be the problem?
Re: Save a value in a Dialog [+REP] -
Konstantinos - 20.05.2016
extracted_ID should not be an array as the "i" specifier is expecting an integer. Do it just like my example.
Re: Save a value in a Dialog [+REP] -
Amit1998 - 20.05.2016
Quote:
Originally Posted by Konstantinos
extracted_ID should not be an array as the "i" specifier is expecting an integer. Do it just like my example.
|
Current code lines:
PHP код:
new extracted_ID;
sscanf(inputtext, "'LotteryID:'i{s[128]}", extracted_ID);
mysql_format(MySQLPipeline, iQuery, sizeof(iQuery), "SELECT * FROM `lotteries` WHERE `ID` = '%d'", extracted_ID);
printf("ID: %i", extracted_ID);
still prints out ID: 0
:/
Re: Save a value in a Dialog [+REP] -
Konstantinos - 20.05.2016
How inputtext looks like? If the text of it is "Lottery ID: ..." and you have in sscanf "LotteryID: ...", it will fail because it couldn't find that text.
Re: Save a value in a Dialog [+REP] -
PrO.GameR - 20.05.2016
If you are using DIALOG STYLE TABLIST or with headers, there is a bug which inputtext only holds info before the first '\t' so you really need to put the ID in first tab.
other than that it's probably what what ^^ he said.