SA-MP Forums Archive
Insert a string into a variable - 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: Insert a string into a variable (/showthread.php?tid=378655)



Insert a string into a variable - Deal-or-die - 18.09.2012

Ergh.. It's late and I am forgetting the simplest of all things.. Ahh..

How would I put 'inputtext' into 'Businessname'?

example
pawn Код:
Business[playerid][bName] = inputtext;
As the line above produces this error
Код:
error 047: array sizes do not match, or destination array is too small



Re: Insert a string into a variable - ViniBorn - 18.09.2012

Use format

Ex:
pawn Код:
format(Business[playerid][bName],sizeof Business[playerid][bName], "%s", inputtext);



Re: Insert a string into a variable - Deal-or-die - 18.09.2012

Ahh of course, Cheers.

This gave me too many errors
pawn Код:
format(Business[playerid][bName],sizeof Business[playerid][bName], "%s", inputtext);
So I just used this instead
pawn Код:
format(Business[playerid][bName],50,inputtext);
Also when checking if the input was empty, how would I do that?

This gives me an error but must be something similar
pawn Код:
if(!strcmp(inputtext, 0, false))
                {
                    SendClientMessage(playerid, COLOR_GREY, "Please insert a name or return to the menu.");
                }
Guess I'd just use
pawn Код:
if(isnull(inputtext))
                {
                    SendClientMessage(playerid, COLOR_GREY, "Please insert a name or return to the menu.");
                }



Re: Insert a string into a variable - Wesley221 - 18.09.2012

Use strcat() instead of the format method, works better. (had problems myself with format)

Also, to check the input: strlen().