strtok
#1

After looking at its definition on samp wiki i reallly dont get what strtok dose or means can someone tell me in bassic terms :P i am reallly new at this so i gota know
Reply
#2

It's used to find a variable after a space. Like a command /ban <playerid>. It will not work if you do /ban5 ( Trying to ban id 5 ). So strtok finds the variable after a space so you can do /ban 5 ( Bans id 5 ). The parameters are explained like this ( in my way ):

const string[], &index
The const string[] is to search a string and find a variable after the space, so like in OnPlayerCommandText, strtok looks for a space ( Like the example above /ban (THE SPACE) 5 ) after the command you put in.

The &index is not something I don't understand 100%, but all I know is that it's used to store a random variable and it's needed for the function to run.

I'll show you a strtok examples.

pawn Код:
public OnPlayerText(playerid, text[]) {
  new ptext[128], rvar;
  ptext = strtok(text, rvar);
  if(strcmp(ptext, "@", true) == 0)
  {
    if(!strlen(ptext)) return SendClientMessage(playerid, MY_COLOR, "@ <Admin chat message>");
  }
}
strlen checks the length of a string. So if strlen is 0 that means it will return. So read closely, I will explain how this worked out.

if(!strlen(ptext))

if = if
!strlen(ptext) = The string text is 0.

So if the string text is 0 then return that message.
Translated
If there's no space between @ and the message, then return that message


Do you understand now?
Reply
#3

Quote:
Originally Posted by Carlton
It's used to find a variable after a space. Like a command /ban <playerid>. It will not work if you do /ban5 ( Trying to ban id 5 ). So strtok finds the variable after a space so you can do /ban 5 ( Bans id 5 ). The parameters are explained like this ( in my way ):

const string[], &index
The const string[] is to search a string and find a variable after the space, so like in OnPlayerCommandText, strtok looks for a space ( Like the example above /ban (THE SPACE) 5 ) after the command you put in.

The &index is not something I don't understand 100%, but all I know is that it's used to store a random variable and it's needed for the function to run.

I'll show you a strtok examples.

pawn Код:
public OnPlayerText(playerid, text[]) {
  new ptext[128], rvar;
  ptext = strtok(text, rvar);
  if(strcmp(ptext, "@", true) == 0)
  {
    if(!strlen(ptext)) return SendClientMessage(playerid, MY_COLOR, "@ <Admin chat message>");
  }
}
strlen checks the length of a string. So if strlen is 0 that means it will return. So read closely, I will explain how this worked out.

if(!strlen(ptext))

if = if
!strlen(ptext) = The string text is 0.

So if the string text is 0 then return that message.
Translated
If there's no space between @ and the message, then return that message


Do you understand now?
Yes thanks very much
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)