Sql & PVars
#1

Hey guys, I just can't figure it out, what I'm trying to do is to combine 2 different strings into 1 to explain it a bit, I'm just learning a bit about sql, and database and so on so what I'm trying to save is the following, I'm using dialog where I insert a name, and I'm using another dialog where I insert lastname saving them to two different PVars.
However I want to combine those 2 (name and lastname) PVars into 1 and to save it as full name.

So what I tried to do is the following:

Dialog Response for inserting the name
Код:
			new charname[128];
            format(charname,sizeof(charname),"%s",inputtext);
			SetPVarString(playerid,"CharName",charname);
Dialog Response for inserting the lastname
Код:
new charlastname[128];
			format(charlastname,sizeof(charlastname),"%s",inputtext);
			SetPVarString(playerid,"CharLastName",charlastname);
"Function" and few commented attempts what I tried to do to combine those two strings:

Код:
SetCharName(playerid)
{
	new setname[128];
	new fname[128];
	new lname[128];
	//format(setname,sizeof(setname),"%s_%s",CharData[playerid][CharName],CharData[playerid][CharLastName]);
	//format(setname,sizeof(setname),"%s_%s",GetPVarString(playerid, "CharName", setname, sizeof(setname)),GetPVarString(playerid, "CharLastName", setname, sizeof(setname)));
	//SetPlayerName(playerid,setname);
	
	format(setname,sizeof(setname),"%s_%s",GetPVarString(playerid, "CharName", fname, sizeof(fname))  ,GetPVarString(playerid, "CharLastName", lname, sizeof(lname)));
	SetPVarString(playerid, "PlayerName", setname);
 	GetPVarString(playerid, "PlayerName", setname, sizeof(setname));
	return 1;
}
And how I tried to save:

Код:
format(szQuery, sizeof(szQuery), "INSERT INTO `characters` (username, yearofbirth, monthofbirth, dayofbirth) VALUES ('%s', '%d', '%d','%d')", SetCharName(playerid) //code goes on...
Just can't figure it out how I can combine and save two strings into one so it will be saved as full name firstname_lastname. Thanks for answer in advance as this is eating my nerves

I know the code at the end went messy but I tried a lot of stuff to make it work, so I just posted the last attempt what I tried.
Reply
#2

Uh, try creating the function this way...

SetCharName(playerid, firstname, lastname)
{
put your save code in here and use firstname to save the first name and lastname to save the last name.

}

And then after you save both variables just call the function this way
SetCharName(playerid, firstnamevar, lastnamevar);


Like.. lets say that you use first dialog for firstname
save what the player entered in a variable

PHP код:
new name[2];
name[0] = "Jack"
and then show the second dialog, save what he entered in another variable, or use a 2d

PHP код:
name[1] = "Rickman" 
And when you call the function

PHP код:
SetCharName(playeridname[0], name[1]); 
the code that is under that function will run, you will probably put the save code there.

So if you've made the function this way
PHP код:
SetCharName(playeridfirstnamelastname
then you will use firstname to save name[0] which is jack, and lastname to save name[1] which is Rickman


and to combine them just use

PHP код:
format(stringsizeof(string), "%s_%s"firstnamelastname);
inside the function 
Reply
#3

Yeah problem is cuz my save code / string combine code doesn't work ^^ so need someone to correct my mistake or to lead me in right direction somehow.
Reply
#4

Quote:
Originally Posted by Lajko1
Посмотреть сообщение
Yeah problem is cuz my save code / string combine code doesn't work ^^ so need someone to correct my mistake or to lead me in right direction somehow.
If you make the function as I told you, you should be able to combine them by just doing this...

PHP код:
format(stringsizeof(string), "%s_%s"firstnamelastname); 
Reply
#5

Код:
new charname[128];
            format(charname,sizeof(charname),"%s",inputtext);
			SetPVarString(playerid,"CharName",charname);
And how to save this properly into variable? it's inputtext dialog, is my way correct or..?
Reply
#6

Quote:
Originally Posted by Lajko1
Посмотреть сообщение
Код:
new charname[128];
            format(charname,sizeof(charname),"%s",inputtext);
			SetPVarString(playerid,"CharName",charname);
And how to save this properly into variable? it's inputtext dialog, is my way correct or..?
Create the variable somewhere at the top to be global... and probably

format(charname, sizeof(charname),"%s", inputtext);

variable = charname;

didn't work too much with dialogs but this should work.
Reply
#7

will try to do your way, however if I use this:

Код:
new charname[128];
            format(charname,sizeof(charname),"%s",inputtext);
			SetPVarString(playerid,"CharName",charname);
and try with this:

Код:
CMD:test(playerid, params[])
{
	new msg[28];
	format(msg, sizeof(msg),"%s",GetPVarString(playerid,"CharName",msg, sizeof(msg)));
	SendClientMessage(playerid,-1,msg);
	return 1;
}
it says "1" and nothing else, soo I used PVars in wrong way (still learning about PVars) or something is wrong at dialogs phase where I'm trying to save to PVar.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)