SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help

Reply
 
Thread Tools Display Modes
Old 07/12/2017, 11:11 AM   #1
Voxel
Gangsta
 
Voxel's Avatar
 
Join Date: Sep 2013
Location: The Netherlands
Posts: 588
Reputation: 68
Default Saving age from dialog to SQLite

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:

Code:
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);

	    }
     }
}
__________________
My Work:
[GameMode]The Nether Survival
[Filterscript]SQLite Database Start
[Tutorial]SQLite Commands
[Tutorial]Loot/ Inventory System
[Tutorial]Simple Hunger/Thirst System
[Tutorial]Converting Binary
[Map]Tropical Island + Pier
[Map]San Fierro Apocalypse
Voxel is offline   Reply With Quote
Old 07/12/2017, 11:29 AM   #2
Unrea1
Gangsta
 
Unrea1's Avatar
 
Join Date: Oct 2013
Location: Venezuela
Posts: 863
Reputation: 123
Default Re: Saving age from dialog to SQLite

PHP Code:
public OnDialogResponse(playeriddialogidresponselistiteminputtext[])
{
     if(
dialogid == 3)
     {
        if(
response)
        {
            new 
Query[1000];

            
User[playerid][USER_AGE] = strval(inputtext);

            
format(Querysizeof(Query), "UPDATE users SET age = %d"User[playerid][USER_AGE]);
            
db_query(DatabaseQuery);
        }
    }

Unrea1 is offline   Reply With Quote
Old 07/12/2017, 11:42 AM   #3
Voxel
Gangsta
 
Voxel's Avatar
 
Join Date: Sep 2013
Location: The Netherlands
Posts: 588
Reputation: 68
Default Re: Saving age from dialog to SQLite

Quote:
Originally Posted by Iszcegg View Post
PHP Code:
public OnDialogResponse(playeriddialogidresponselistiteminputtext[])
{
     if(
dialogid == 3)
     {
        if(
response)
        {
            new 
Query[1000];

            
User[playerid][USER_AGE] = strval(inputtext);

            
format(Querysizeof(Query), "UPDATE users SET age = %d"User[playerid][USER_AGE]);
            
db_query(DatabaseQuery);
        }
    }

Works! Thank you.
__________________
My Work:
[GameMode]The Nether Survival
[Filterscript]SQLite Database Start
[Tutorial]SQLite Commands
[Tutorial]Loot/ Inventory System
[Tutorial]Simple Hunger/Thirst System
[Tutorial]Converting Binary
[Map]Tropical Island + Pier
[Map]San Fierro Apocalypse
Voxel is offline   Reply With Quote
Old 07/12/2017, 12:35 PM   #4
Dayrion
High-roller
 
Dayrion's Avatar
 
Join Date: Jan 2016
Location: France
Posts: 1,868
Reputation: 255
Default Re: Saving age from dialog to SQLite

PHP Code:
format(Querysizeof(Query), "UPDATE users SET age = %d"User[playerid][USER_AGE]); 
Will update every users's age to the current value, no?
__________________
actor_plus - v5.0.0
I'm a goner, somebody catch my breath,
I'm a goner, somebody catch my breath
Dayrion is offline   Reply With Quote
Old 07/12/2017, 12:40 PM   #5
Calgon
Godfather
 
Calgon's Avatar
 
Join Date: Jan 2009
Posts: 6,487
Reputation: 1126
Default Re: Saving age from dialog to SQLite

Quote:
Originally Posted by Voxel View Post
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 View Post
PHP Code:
format(Querysizeof(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.
Calgon is offline   Reply With Quote
Old 07/12/2017, 01:21 PM   #6
Konstantinos
Spam Machine
 
Konstantinos's Avatar
 
Join Date: Dec 2011
Posts: 11,983
Reputation: 1392
Default Re: Saving age from dialog to SQLite

Quote:
Originally Posted by Calgon View Post
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).
__________________
Life is like riding a bicycle. To keep your balance, you must keep moving.

[Tutorial] How to use SQLite
[FilterScript] Tune System
Konstantinos is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
SQLite and saving date FailerZ Scripting Help 0 09/06/2017 06:56 PM
Saving to SQLite Johnny_Robins Scripting Help 0 13/05/2014 11:57 AM
Saving into sqlite. Unri Scripting Help 6 27/09/2013 08:28 PM
[HELP] sqlite saving in FS bugs other FS's? <Weponz> Help Archive 0 31/12/2010 03:34 PM


All times are GMT. The time now is 11:42 AM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.