Saving age from dialog to SQLite - Printable Version
+- SA-MP Forums Archive (
https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (
https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (
https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Saving age from dialog to SQLite (
/showthread.php?tid=645932)
Saving age from dialog to SQLite -
Voxel - 07.12.2017
Hey yall, im trying to save the age from an inputtext from an dialog.
I played around with it for around an hour or two but I cant get it to work.
I just want to store what ever number the player entered in dialogid 3 and save it to the SQLite database.
Code:
pawn Код:
public OnPlayerSpawn(playerid)
{
new str[2500];
strcat(str,""chat" "COL_WHITE"Enter your age");
ShowPlayerDialog(playerid,3,DIALOG_STYLE_INPUT,""COL_WHITE"Alice",str,"Enter","");
return 1;
}
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
if(dialogid == 3)
{
if(response)
{
new Query[1000];
new amount[128] = inputtext;
User[playerid][USER_AGE] = amount[playerid];
format(Query, sizeof(Query), "UPDATE users SET age = %d", User[playerid][USER_AGE]);
db_query(Database, Query);
}
}
}
Re: Saving age from dialog to SQLite -
Unrea1 - 07.12.2017
PHP код:
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
if(dialogid == 3)
{
if(response)
{
new Query[1000];
User[playerid][USER_AGE] = strval(inputtext);
format(Query, sizeof(Query), "UPDATE users SET age = %d", User[playerid][USER_AGE]);
db_query(Database, Query);
}
}
}
Re: Saving age from dialog to SQLite -
Voxel - 07.12.2017
Quote:
Originally Posted by Iszcegg
PHP код:
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
if(dialogid == 3)
{
if(response)
{
new Query[1000];
User[playerid][USER_AGE] = strval(inputtext);
format(Query, sizeof(Query), "UPDATE users SET age = %d", User[playerid][USER_AGE]);
db_query(Database, Query);
}
}
}
|
Works! Thank you.
Re: Saving age from dialog to SQLite -
Dayrion - 07.12.2017
PHP код:
format(Query, sizeof(Query), "UPDATE users SET age = %d", User[playerid][USER_AGE]);
Will update every users's age to the current value, no?
Re: Saving age from dialog to SQLite -
Calgon - 07.12.2017
Quote:
Originally Posted by Voxel
Works! Thank you.
|
Make sure you reduce Query[1000] down to the amount of characters you actually need there, it looks like you're using under 30 characters. You will reduce memory usage in your AMX by making sure you don't have such large strings.
Query[30] will be fine.
Quote:
Originally Posted by Dayrion
PHP код:
format(Query, sizeof(Query), "UPDATE users SET age = %d", User[playerid][USER_AGE]);
Will update every users's age to the current value, no?
|
No. Read the code, the age variable is set BEFORE the query.
Re: Saving age from dialog to SQLite -
Konstantinos - 07.12.2017
Quote:
Originally Posted by Calgon
No. Read the code, the age variable is set BEFORE the query.
|
Dayrion does not refer to variable. It WILL update the age of all users
in the table unless
WHERE clause is used to identify the user (by registration id or name).