Author Topic: Weird searching with a group object (same name issue?)  (Read 5147 times)

So I have been having issues with this code.

function VisoShopServer::findMember(%this,%string)
{
   if(!isObject(%this)) return -1;
   for(%i=0;%i<%this.memberCount + 1;%i++)
   {
      if(isObject(%string))
         if(%string.getClassName() $= "ItemData")
            if(%string.uiName $= %this.member[%i].uiName)
               return %this.member[%i];
      if(!isObject(%string))
         if(strPos(%this.member[%i].uiName,%string) >= 0)
            return %this.member[%i].getName();
   }
   if(getFieldCount(%members) <= 0)
      return 0; //Client was never in this group
}


There are a few related weapons with their attached shop object.

Name: Modern Pistol     ItemObj: ModernPistolItem    ShopObj: VisoShopServItem_Pistols_Modern_Pistol
Name: Modern Pistols A.     ItemObj: AkimboModernPistolItem    ShopObj: VisoShopServItem_Pistols_Modern_Pistols_A

When I do
talk(VisoShop_ServSECGroup.findMem ber("Modern Pistol"));
This returns
==> VisoShopServItem_Pistols_Mode rn_Pistols_A
This means that it's returning the "Modern Pistols A."'s shop object for some reason, is there any way to fix this?

The VisoShopServItem_* is a script object that keeps an item's cached damage, cost, radius damage, description of the shop weapon, ui name, and the item data's name.
The shop objects are inside the VisoShopServer class.
« Last Edit: February 18, 2015, 12:06:32 AM by Advanced Bot »

I'm going to assume that Modern Pistol A. is appearing in the list before Modern Pistol, and since strPos will find "Modern Pistol" in "Modern Pistol A.", it'll just return that.

Why are you adding one to the for loop end condition? You're just going to get an index out of range error on the last run
Also, the %members variable you're referencing at the end is never defined.

Shift's answer sounds right
You'll probably have to do the lookup by item name, or something else that can uniquely identify it
« Last Edit: February 18, 2015, 08:42:23 AM by Headcrab Zombie »