SA-MP Forums Archive
How to set a variable to string - 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: How to set a variable to string (/showthread.php?tid=572383)



How to set a variable to string - aCloudy - 27.04.2015

Hello.
Can someone how to set something to string not to a number.
Example:
Код:
label = params;
But the code above won't work because "params" is not a number, Can someone tell me what is the function to set label string params ?


Re: How to set a variable to string - J4Rr3x - 27.04.2015

EDIT:
pawn Код:
strpack(label, params);
// You also can use also 'format' but in this case you don't need to format string and 'strpack' is much faster



Re: How to set a variable to string - Evocator - 27.04.2015

label = strval(params) ?


Re: How to set a variable to string - SickAttack - 27.04.2015

Convert a string to an integer:
https://sampwiki.blast.hk/wiki/Strval

Convert an integer into a string:
https://sampwiki.blast.hk/wiki/Valstr


Re: How to set a variable to string - (SF)Noobanatior - 28.04.2015

pawn Код:
new string[24] = "up to 24 letters";
like this?

actually do you mean like this
pawn Код:
new label[24];
copy(label,params,sizeof(label));



Re: How to set a variable to string - Ciarannn - 28.04.2015

Do you mean like:

pawn Код:
new label[128];
format(label, sizeof(label), "%s", params);



Re: How to set a variable to string - Vince - 28.04.2015

Quote:
Originally Posted by J4Rr3x
Посмотреть сообщение
EDIT:
pawn Код:
strpack(label, params);
// You also can use also 'format' but in this case you don't need to format string and 'strpack' is much faster
Are you confused with strcpy? Strpack, as its name suggests, packs the string to use less space. However, many functions do not work well, or even at all with packed strings so you'll need to unpack it first before using it.