Find string in array
#1

Hi!

I'm trying to make a chat with a bot and I don't know how to find a string inside an array, for example:

Quote:

new Chat[4][128] =
{
"hi",
"how are you?",
"hello",
"ajsdknjsd"
};

if(strfind(text, SEARCH_ARRAY_OF_ANSWERS) != -1) <- I want to check the "Chat" array for the possible answers a player can make. I dont wanna be full of "if" or "elses"

Anyone got a clue?
Reply
#2

Any one has a clue?

My FS depends on this :P

There's has to be a way of doing this!
Reply
#3

Code:
new Chat[4][128] =
{
    "hi",
    "how are you?",
    "hello",
    "ajsdknjsd"
};
Code:
new i,j;

for(i=0;i<4,i++)
{
  for(j=0;j<128,j++)
  {
    if(!strcmp(cmdtext,Chat[i][j],false) return SendClientMessage(playerid,0xffffffaa,"You are answer wasn't understood by me Sir.");
  
    //then your script here

  }
}
I am not sure coz I learned C++ and maybe it might work. Try something like that.
Reply
#4

Could use strlib (by Westie), there's a specific function for this.
Reply
#5

pawn Code:
new
    Array[][] =
    {
      "Hi",
      "How are you?",
      "Hello",
      "ajsdknjsd"
    }
;
pawn Code:
new
    x
;
for(;;)
{
    //printf("%s", Array[x]);
    if(strfind(Array[x], "Hi") != -1)
    {
        // The rest of you code
    }
    if(x > sizeof(Array)) break;
    x++;
}
Reply
#6

Quote:
Originally Posted by Calgon
Could use strlib (by Westie), there's a specific function for this.
That worked great!

Thanks everybody!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)