Blockland Forums > Modification Help
Find The Closet Matching String
DontCare4Free:
--- Quote from: Treynolds416 on March 21, 2012, 02:19:42 PM ---My point is that you don't need several returns
Edit: I just took a better look at your code. Why also are you setting three variables to %file.readLine();?
--- End quote ---
One variable for each line.
Treynolds416:
Oh, I see what you were trying to do.
You should instead try putting a name then a space and then the ID. getWord would be used to get the ID value.
jes00:
--- Quote from: Treynolds416 on March 21, 2012, 07:16:30 PM ---Oh, I see what you were trying to do.
You should instead try putting a name then a space and then the ID. getWord would be used to get the ID value.
--- End quote ---
But I don't want to do that.
The point is the code I posted does not work.
Nexus:
you don't need a while loop if you know how many times you are going to loop, unless you didn't know what you were doing when you added a delete and return at the end of the while loop. The thing will stop looping if it hits a return, of course.
I'm not really understanding the if statement you have. You also have no way of comparing lines to eachother when more than one possible match is found.
I'm not familiar with the strstr() function, so I am going to write this with an imaginary function strcom() which will return a float between 0 and 1 depending on how similar the strings are. It will return a 1 with a perfect match.
--- Code: ---function getID(%name)
{
%file = new FileObject();
%file.openForRead("config/Client/ChatBot/BL_IDs.txt");
%bestid = "-1";
while(!%file.isEOF())
{
%badName = %file.readLine();
%ID = %file.readLine();
%blank = %file.readLine();
%match = strcom(%badname, %name);
if(%match > %bestmatch)
{
%bestmatch = %match;
%bestid = %id;
if(%bestmatch == 1)
break;
}
}
%file.close();
%file.delete();
return %bestid;
}
--- End code ---
jes00:
--- Quote from: Nexus on March 21, 2012, 09:22:58 PM ---you don't need a while loop if you know how many times you are going to loop, unless you didn't know what you were doing when you added a delete and return at the end of the while loop. The thing will stop looping if it hits a return, of course.
I'm not really understanding the if statement you have. You also have no way of comparing lines to eachother when more than one possible match is found.
I'm not familiar with the strstr() function, so I am going to write this with an imaginary function strcom() which will return a float between 0 and 1 depending on how similar the strings are. It will return a 1 with a perfect match.
--- Code: ---function getID(%name)
{
%file = new FileObject();
%file.openForRead("config/Client/ChatBot/BL_IDs.txt");
%bestid = "-1";
while(!%file.isEOF())
{
%badName = %file.readLine();
%ID = %file.readLine();
%blank = %file.readLine();
%match = strcom(%badname, %name);
if(%match > %bestmatch)
{
%bestmatch = %match;
%bestid = %id;
if(%bestmatch == 1)
break;
}
}
%file.close();
%file.delete();
return %bestid;
}
--- End code ---
--- End quote ---
That's not too useful because as it is strCom() does not exist.