"/car" help | need some direction
#1

Hi, I was looking through a few scripts I had on my computer and I don't understand what the following means entirely.

Код:
if(IsPlayerConnected(playerid))
	    {
   			new x_v[256];
		    x_v = strtok(cmdtext, idx);
			if(!strlen(x_v))
			{
				SendClientMessage(playerid, COLOR_WHITE, "Server: /car [name]");
		  		SendClientMessage(playerid, COLOR_WHITE, "Available names: engine, hood, trunk, lights");
				return 1;
			}
I understand that it checks if the player is connected and it will send them a message, but I don't understand

Код:
 	new x_v[256];
		    x_v = strtok(cmdtext, idx);
			if(!strlen(x_v))
Could someone provide some assistance please for a push in the right direction? Much appreciated.
Reply
#2

x_v is simply a string that has a 256 string size. Now, strtok is used to find what is typed AFTER a space, so this code simply states that if the player does not type in anything after a space (or does not type a space) it will sow the message.

EDIT: More on strtok can be found HERE

EDIT2: Forgot about the strlen part, strlen is used to get the length of the string, so lets say the string is test, the length is 4. Now, what it is checking is if there is no size, meaning it is 0, and so it will show the message.
Reply
#3

Thank you! This has been a great help considering how I haven't been able to get a clear answer. This has really helped me understand this section of the script.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)