Author Topic: Strange Errors in Player Database Searcher  (Read 1673 times)

Hello, I've made a searcher for my player database, it includes filters, patterns, etc. and is always supposed to produce human-readable output.
For the most part it works, but the function is very large, and i'm having trouble finding the problem with it.
The function takes in the following format:
Type Filter Pattern Value

ex.:
Name Current Equals blah

Inputting that would work fine. The problem is with input like this:
Name 5 Contains something
Which would just output "ERROR", or "Contains Something!". I cannot find the cause of this, but if anyone can help me, this is the code, (note that the function is over 200 lines long as it needs to produce human-readable output):
Code: [Select]
function findMatches(%Args)
{
%Type = strLwr(getWord(%Args, 0));
%WordCount = getWordCount(%Args);
if(%Type $= "name")
{
if(%WordCount < 4 && %WordCount > 2)
{
%Pattern = "Contains";
%Filter = getWord(%Args, 1);
%Value = getWords(%Args, 2, %WordCount);
}
else if(%WordCount == 2)
{
%Filter = "Any";
%Pattern = "Contains";
%Value = getWord(%Args, 1);
}
else if(%WordCount > 3)
{
%Filter = getWord(%Args, 1);
%Pattern = getWord(%Args, 2);
if(%Pattern $= "contains")
%Pattern = "Contains";
%Value = getWords(%Args, 3, %WordCount);
}
else
{
error("Not enough arguments in Input (" @ %Args @ ") for function findMatches! Ending function...");
return false;
}
echo(%Filter SPC %Pattern SPC %value);
if(%Filter $= "0")
return findMatches(%Type SPC "Current" SPC %Pattern SPC %Value);
for(%a = 0; %a < LoggerSS.getCount(); %a++)
{
%Log = LoggerSS.getObject(%a);
%NameCount = %Log.NameCount;
%filtemp = %Filter;
switch$(%Filter)
{
case "Current":
%Name = %Log.CurrentName;
case "First":
%Name = %Log.Name0;
default:
if(isInt(%Filter))
{
if(%NameCount == 1 && %Filter > %NameCount)
continue;
else if(%NameCount > 1 && %Filter > %NameCount)
%Filtemp = %NameCount;
else if(%Filter < 0)
{
error("Invalid filter (" @ %Filter @ ") entered for findMatches! Ending function...");
return false;
}
%Name = %Log.Name[%Filter - 1];
echo(%Name);
}
else
return "Filter Not Recognized.";
}
switch$(%Pattern)
{
case "Begins":
if(strPos(%Name, %Value) != 0)
continue;
case "Ends":
if(strLen(%Name) < strLen(%Value) || getSubStr(%Name, strLen(%Name) - strLen(%Value), strLen(%Value)) !$= %Value)
continue;
case "Contains":
if(strPos(%Name, %Value) < 0)
continue;
case "Equals":
if(%Value !$= %Name)
continue;
else
{
%Result = %Log SPC %Name;
%ResultCount++;
continue;
}
case "NotBegin":
if(strPos(%Value, %Name) == 0)
continue;
case "NotEnds":
if(strPos(%Value, %Name) == strLen(%Name) - strLen(%Value))
continue;
case "NotContains":
if(strPos(%Value, %Name) >= 0)
continue;
case "NotEquals":
if(%Value $= %Name)
continue;
default:
return "Pattern Not Recognized.";
}
%Result[%ResultCount++] = %Log SPC %Name;
%Filtemp[%ResultCount] = %Filtemp;
}
switch$(%Filter)
{
case "Current":
if(%ResultCount > 1 && strPos("equals", %Pattern) < 0)
{
%Message = "Results: ";
for(%a = 1; %a < %ResultCount; %a++)
%Message = %Message SPC getWords(%Result[%a], 1, getWordCount(%Result[%a])) SPC "- " @ getWord(%Result[%a], 0).BL_ID @ ",";
%Message = %Message SPC getWords(%Result[%ResultCount], 1, getWordCount(%Result[%ResultCount])) SPC "- " @ getWord(%Result[%ResultCount - 1], 0).BL_ID;
return %Message;
}
else if(%Pattern $= "Equals")
{
if(%ResultCount != 0)
%Message = "The Player Named " @ %Value @ ": " @ getWord(%Result, 1) SPC "- " @ getWord(%Result, 0).BL_ID;
else
%Message = "I have not seen any players with the name " @ %Value @ "!";
return %Message;
}
else
{
if(%ResultCount != 0)
%Message = "The Player whoose Name ";
else
%Message = "I have not seen anyone whoose Name ";
}
case "First":
if(%ResultCount > 1)
%Message = "Players First Names ";
else if(%ResultCount == 1)
{
if(%Pattern $= "Equals")
{
%Message = "The Player With the First Name" SPC %Value @ ":" SPC getWord(%Result, 1) SPC "-" SPC getWord(%Result, 0).BL_ID;
return %Message;
}
else
%Message = "The Player whoose First Name ";
}
else
%Message = "I have not seen any players whoose First Name ";
default:
if(isInt(%Filter))
{
%Num = %Filter;
%Len = strlen(%Num);
if(getSubStr(%Num, %Len - 2, 1) == 1)
%Num = %Num @ "th";
else if(getSubStr(%Num, %Len - 1, 1) == 1)
%Num = %Num @ "st";
else if(getSubStr(%Num, %Len - 1, 1) == 2)
%Num = %Num @ "nd";
else if(getSubStr(%Num, %Len - 1, 1) == 3)
%Num = %Num @ "rd";
else
%Num = %Num @ "th";
if(%ResultCount > 1)
%Message = "Players whoose" SPC %Num SPC "Name ";
}
else
return "Error";
}
if(%ResultCount > 1)
{
switch$(%Pattern)
{
case "Begins":
%Message = %Message @ "Beginning with " @ %Value @ ":" SPC %ResultCount SPC "-";
case "Ends":
%Message = %Message @ "Ending with " @ %Value @ ":" SPC %ResultCount SPC "-";
case "Contains":
%Message = %Message @ "Contain " @ %Value @ ":" SPC %ResultCount SPC "-";
case "NotBegin":
%Message = %Message @ "Not Beginning with " @ %Value @ ":" SPC %ResultCount @ ".";
return %Message;
case "NotEnds":
%Message = %Message @ "Not Ending with " @ %Value @ ":" SPC %ResultCount @ ".";
return %Message;
case "NotContains":
%Message = %Message @ "Not Containing " @ %Value @ ":" SPC %ResultCount @ ".";
return %Message;
default:
return "ERROR";
}
for(%a = 1; %a < %ResultCount - 1; %a++)
%Message = %Message SPC getWord(%Result[%a], 1) SPC "-" SPC getWord(%Result[%a], 0).BL_ID @ ",";
}
else if(%ResultCount == 0)
switch$(%Pattern)
{
case "Begins":
%Message = %Message @ "Begins with " @ %Value @ "!";
case "Ends":
%Message = %Message @ "Ends with " @ %Value @ "!";
case "Contains":
%Message = %Message @ "Contains " @ %Value @ "!";
case "NotBegin":
%Message = %Message @ "Does Not Begin with " @ %Value @ "!";
case "NotEnds":
%Message = %Message @ "Does Not End with " @ %Value @ "!";
case "NotContains":
%Message = %Message @ "Does Not Contain " @ %Value @ "!";
default:
return "ERROR";
}
else if(%ResultCount == 1)
{
switch$(%Pattern)
{
case "Begins":
%Message = %Message @ "Begins with " @ %Value @ ":";
case "Ends":
%Message = %Message @ "Ends with " @ %Value @ ":";
case "Contains":
%Message = %Message @ "Contains " @ %Value @ ":";
case "NotBegin":
%Message = %Message @ "Does Not Begin with " @ %Value @ ":";
case "NotEnds":
%Message = %Message @ "Does Not End with " @ %Value @ ":";
case "NotContains":
%Message = %Message @ "Does Not Contain " @ %Value @ ":";
default:
return "ERROR";
}
return %Message SPC getWord(%Result1, 1) @ "," SPC getWord(%Result1, 0).BL_ID;
}
return %Message;
}
else if(%Type $= "blid" || %Type $= "bl_id" || %Type $= "id")
{
switch(%WordCount)
{
case 2:
%Pattern = "Equals";
%Value = getWord(%Args, 1);
case 3:
%Pattern = getWord(%Args, 1);
%Value = getWord(%Args, 2);
if(!isInt(%Value) || (%Value < 0 || (%Value > 0 && %Value < 100) || %Value > 40000))
{
error("Incorrect BLID (" @ %Value @ ") Entered for findMatches! Ending function...");
return false;
}
default:
error("Incorrect argument count in Input (" @ %Args @ ") for function findMatches! Ending function...");
return false;
}
}
}
There is also a strange getSubStr error once it reaches the last player log in the loop, which I cannot figure out the cause.

Your example makes no sense, can you please give a better one?

More examples:
Name First Ends gh
should find all people whoose first recorded name ends with gh.

Name 3 Contains ab
should find all people whoose 3rd recorded name contains ab.

Name Current Begins li
should find all people whoose last recorded name begins with li.

I have only looked at the id lookup part so far
Two relatively minor things:
- It doesn't do anything other than making sure the arguments are valid (you know this I hope)
- And also kompressor has an id of 1, so the part in the if statement that goes something like
Code: [Select]
|| (%Value > 0 && %Value < 100)should actually be
Code: [Select]
|| (%Value > 1 && %Value < 100)
Like I said, minor things. I'll look through the rest of this monolithic beast later
« Last Edit: May 03, 2012, 10:03:01 PM by Treynolds416 »

- It doesn't do anything other than making sure the arguments are valid (you know this I hope)
Yes I know this, if there is *supposed* invalid input, it will return "ERROR".
and on the > 0, that was probably a stupid little logic misthink, no wonder I diddnt notice it though.
I don't think of this as monolithic, everything that's in there is in for a reason, and would produce further undesirable results if removed.

you should break this up into a few functions for best debugging.

Good idea, i'll give that a try. But besides that, can you see anything initially incorrect?

Good idea, i'll give that a try. But besides that, can you see anything initially incorrect?
I was too frightened to look at it, sorry.

I was too frightened to look at it, sorry.
In that case, I'll comment the script so it's understandable tommorow.

In that case, I'll comment the script so it's understandable tommorow.
I've already found a few things
I'm going to add comments to the whole block script once I get through all of it

I've already found a few things
I'm going to add comments to the whole block script once I get through all of it
Wow thanks, and just so you know, the script only works on name queries, because I havn't finished the BLID search yet, allthough that part would be much easier to make.