Author Topic: (Solved) Client Database  (Read 1467 times)

So I have this client add-on, I have by no means created it myself, I was trying to get it to work. It was created by Lilboarder using Zack0Wack0's database blockByte.
When I got it I couldn't get it to return anything at all, I have fixed the ID look-up aspect, however the name look-up still has an error. It will return the name, as well as tell me how many results for the name it has found, but it will only list one name instead of multiple.

Code: [Select]
package updateList
{
function NMH_Type::Send(%this)
{
%Msg = %this.getValue();
if(getWord(%Msg,0) $= "/WhoIs")
{
%args = getWords(%msg,1,getWordCount(%msg));
if(getWord(%args,0) > 0)
{
Blahblah ID lookup
}

else
{
%returnName = findName(%args);
if(%returnName == -1)
{
if(!%foundBLID)
{
clientCmdChatMessage("","","","\c3Database\c6: The search has returned no results for the name "@ %args @".","");
}
%this.setValue("");
Parent::Send(%this);
return;
}


else
{
%currName = getField(%returnName,%i);

%blid = LilDatabaseSO.value[%currName,"clientBLID"];
%lastSeen = LilDatabaseSO.value[%currName,"lastSeen"];
%oldName = LilDatabaseSO.value[%currName,"previousAliases"];

if(%oldName !$= "null")
{
%oldNameString = " - Previous Name: "@ %oldName;
}
else
{
%oldNameString = "";
}
%count = getFieldCount(%returnName);
%s = %count > 1 ? "s" : "";


if(%i == 0)
{
clientCmdChatMessage("","","","\c3Database\c6: "@ %count @" result"@ %s @" for "@ %args @".","");
clientCmdChatMessage("","","","\c3Database\c6: Name: "@ %currName @" - BL_ID: "@ %BLID @" - Last Seen: "@ %lastSeen SPC %oldNameString,"");
}
else
{
clientCmdChatMessage("","","","\c3Database\c6: Name: "@ %currName @" - BL_ID: "@ %BLID @" - Last Seen: "@ %lastSeen SPC %oldNameString,"");
}
}

}
%this.setValue("");
}
Parent::Send(%this);
}
blah blah

I have a feeling I may need
Code: [Select]
for(%i=1;%i<=%count;%i++) in there somewhere but I'm at a loss.
« Last Edit: May 12, 2014, 03:06:57 PM by Thorfin25 »

I think your problem might be related to the fact that %returnName is list where each word is separated by tabs, and I don't think tabs display correctly in the chat.  It might be helpful for debugging if you add echo statements to give you relevant information in console when your code is executed.

Well, the %returnName does come back as a list such as that, but that's where getField(%returnName,%i); comes into play. I added some echos and changed the script a little, got it to work a little better, but it spams me one extra line of chat.






Code: [Select]
else
{
// echo(%args);
// echo(findName(%args,%i));
%returnName = findName(%args,%i);
if(%returnName == -1)
{
if(!%foundBLID)
{
clientCmdChatMessage("","","","\c4Database\c6: The search has returned no results for the name "@ %args @".","");
}
%this.setValue("");
Parent::Send(%this);
return;
}

%count = getFieldCount(%returnName);
%s = %count > 1 ? "s" : "";
// echo(%count);
if(%returnName != -1)
{

clientCmdChatMessage("","","","\c4Database\c6: "@ %count @" result"@ %s @" for "@ %args @".","");
for(%i=0;%i<=%count;%i++)
{
%currName = getField(%returnName,%i);
echo(%i);
echo(%currName);

%blid = LilDatabaseSO.value[%currName,"clientBLID"];
%lastSeen = LilDatabaseSO.value[%currName,"lastSeen"];
%oldName = LilDatabaseSO.value[%currName,"previousAliases"];

if(%oldName !$= "null")
{
%oldNameString = " - Previous Name: "@ %oldName;
}
else
{
%oldNameString = "";
}



if(%i == 1)
{
// echo(%i);
clientCmdChatMessage("","","","\c4Database\c6: Name: "@ %currName @" - BL_ID: "@ %BLID @" - Last Seen: "@ %lastSeen SPC %oldNameString,"");
}
else
{
clientCmdChatMessage("","","","\c4Database\c6: Name: "@ %currName @" - BL_ID: "@ %BLID @" - Last Seen: "@ %lastSeen SPC %oldNameString,"");
// echo(%i);
}
}
}

The problem is an inherent error with your findName function, but since you didn't post that I can't help you fix the source of the problem, only patch it.

Inside your for loop, after you set %currName, do this: if(%currName $= "") continue;


My bad. I missed the conditional statement inside your for loop which is wrong. You're checking if %i is less than or equal to %count, which gives you an extra result. Basically, you have 2 items, so your for loop is checking items 0, 1, and 2. You only need 0 and 1.
« Last Edit: May 12, 2014, 02:57:03 PM by $trinick »

You're checking if %i is less than or equal to %count, which gives you an extra result.
Thanks a million!

« Last Edit: May 12, 2014, 03:45:40 PM by Thorfin25 »