Strings problem
#1

I'm facing a problem with strings and PVars

so here is the code from dialog response (inputtext style)
I'm trying to save inputtext into the PVarString

Код:
			new charname[128];
            format(charname,sizeof(charname),"%s",strlen(inputtext));
			SetPVarString(playerid,"CharName",charname);
and here is the command which I use to test if it's working:
Код:
CMD:test(playerid, params[])
{
	new msg[28];
	format(msg, sizeof(msg),"%s",GetPVarString(playerid,"CharName",msg, sizeof(msg)));
	SendClientMessage(playerid,-1,msg);
	return 1;
}
The answer I get are some random numbers when I use the command that should display what's in the saved string.
Reply
#2

strlen(); return the string length.
Reply
#3

PHP код:
new charname[128];
format(charname,sizeof(charname),"%s",strval(inputtext));
SetPVarString(playerid,"CharName",charname); 
Try This.
Reply
#4

What's the fuss with all the extra unnecessary (huge) variables? What exactly is preventing you from doing
PHP код:
SetPVarString(playerid"CharName"inputtext); 
and
PHP код:
GetPVarString(playerid"CharName"msgsizeof(msg)); 
Arrays are always passed "by reference" into a function (unless declared const like in SendClientMessage) which means the function can change the original array. In this context it means that "msg" will automagically contain the text stored in the PVar when the function is done. No additional assignment is necessary. GetPVar itself only returns 1 or 0 to denote success or failure.
Reply
#5

None of above worked :/ or it was just me making the code totally messy already as I'm trying to resolve that for hours now.
Reply
#6

format(charname,sizeof(charname),"%s",strlen(input text));

your problem is

strlen(inputtext)

it well return the number xD
inputtext is string itself so if you just put inputtext alone it will help you


so with putting inputtext alone it will define what ever exacly player wrote and set it to charname

i hope you understand

Note that stlen and strval is returning numbers as i know you wanted to save a string so you should use inputtext alon

here what it should be look like

PHP код:
new charname[128];
format(charname,sizeof(charname),"%s",inputtext);
SetPVarString(playerid,"CharName",charname); 
Reply
#7

I don't understand why I'm complicated as woman at scripting, easiest things I will turn into mess and will try to reach impossible, Thank you, repping everyone above
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)