Scripting help - 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)
+---- Forum: Help Archive (
https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: Scripting help (
/showthread.php?tid=249854)
Scripting help -
NitoPSG - 20.04.2011
So i am new scripter and because i want to learn scripting i will ask you a few things to explain me!
1) what is tmp? what is the number in front of this?: tmp[256]
2) what is strtok? what this actually do?
3) what this means? if(!strlen(tmp)) and this weap = strval(tmp); whats this lines do?
Re: Scripting help -
Vince - 20.04.2011
1. This is an array variable. It can contain a string (i.e. text) or a series of numbers. Tmp is an abbreviation for
Te
mporary and is a commonly used name for data that needs to be remembered for a short while.
2. strtok is a function that can split a string into multiple parts, based on a certain delimiter (most commonly space) and is mostly used for making commands with additional parameters. However, strtok is old and outdated and there are far superior ways available to make commands nowadays.
3.
if(!strlen(tmp)) checks if the length of tmp is 'not something', or in other words 0. Actually, strlen returns the numbers of characters in a string. e.g. strlen("something") will return 9. The negation operator (!) inverses this effect.
weap = strval(tmp); assigns the numerical value that is stored in tmp (e.g. tmp[256] = "46"

to a new variable called weap. strval (
string
value)converts the string (e.g. "46", note the double quotes) to an integer (e.g. 46).