Skip to content
View in the app

A better way to browse. Learn more.

WRobot

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Code about fuzzy matching

Featured Replies

I'm now trying to write a bit of fuzzy matching code, but it hasn't worked,Following the normal traversal of the target name, the code I used was:
string[] objectNames = new string[] { "Alliance Bonfire" };
foreach (string objectName in objectNames)
    {
          var gameObject = ObjectManager.GetWoWGameObjectByName(objectName)
            .Where(o => o.GetDistance <= maxDistance)
            .OrderBy(o => o.GetDistance)
            .FirstOrDefault();
        if (gameObject != null )
        {......
     }
    }
What I want to achieve is a fuzzy match, which doesn't require a full traversal of the "Alliance Bonfire", just a matching "Bonfire".

  • Author
10 hours ago, Droidz said:

你好

string[] objectNames = new string[] { "Bonfire" };
foreach (string objectName in objectNames)
{
    var gameObjects = ObjectManager.GetObjectWoWGameObject()
        .Where(o => o.Name.Contains(objectName) && o.GetDistance <= maxDistance)
        .OrderBy(o => o.GetDistance)
        .FirstOrDefault();

    if (gameObjects != null)
    {
        // ...
    }
}

 

I tested it and it didn't work with a fuzzy match, and when I tested the full name with PNC "Auctioneer Billdu", I was able to match this PNC, but when I used the fuzzy name "Auctioneer", it didn't match properly, here's my code

string[] objectNames = new string[] { "Auctioneer Billdu" };

float maxDistance = 2250.0f;

while (true)
{
foreach (string objectName in objectNames)
{
    var gameObjects = ObjectManager.GetObjectWoWGameObject()


         
        .Where(o => objectNames.Contains(o.Name) && o.GetDistance <= maxDistance)
        .OrderBy(o => o.GetDistance)
        .FirstOrDefault();

    if (gameObjects != null)
    {
     
                string luaPrintCommand = string.Format("print('Targeted object: {0}')", gameObjects.Name);
                Lua.LuaDoString(luaPrintCommand);
                Thread.Sleep(50);

}
}
}


If you change it to the following code, it will not match the NPC
  
  
string[] objectNames = new string[] { "Auctioneer" };

float maxDistance = 2250.0f;

while (true)
{
foreach (string objectName in objectNames)
{
    var gameObjects = ObjectManager.GetObjectWoWGameObject()


         
        .Where(o => objectNames.Contains(o.Name) && o.GetDistance <= maxDistance)
        .OrderBy(o => o.GetDistance)
        .FirstOrDefault();

    if (gameObjects != null)
    {
     
                string luaPrintCommand = string.Format("print('Targeted object: {0}')", gameObjects.Name);
                Lua.LuaDoString(luaPrintCommand);
                Thread.Sleep(50);

}
}
}

You're not using the elements of your foreach loop. The code Droidz gave you is absolutely correct.

Replace

    var gameObjects = ObjectManager.GetObjectWoWGameObject()        
        .Where(o => objectNames.Contains(o.Name) && o.GetDistance <= maxDistance)
        .OrderBy(o => o.GetDistance)
        .FirstOrDefault();   

with

    var gameObjects = ObjectManager.GetObjectWoWGameObject()        
        .Where(o => o.Name.Contains(objectName) && o.GetDistance <= maxDistance)
        .OrderBy(o => o.GetDistance)
        .FirstOrDefault();   

 

  • Author
On 7/5/2024 at 9:22 AM, Zer0 said:

You're not using the elements of your foreach loop. The code Droidz gave you is absolutely correct.

Replace

    var gameObjects = ObjectManager.GetObjectWoWGameObject()        
        .Where(o => objectNames.Contains(o.Name) && o.GetDistance <= maxDistance)
        .OrderBy(o => o.GetDistance)
        .FirstOrDefault();   

with

    var gameObjects = ObjectManager.GetObjectWoWGameObject()        
        .Where(o => o.Name.Contains(objectName) && o.GetDistance <= maxDistance)
        .OrderBy(o => o.GetDistance)
        .FirstOrDefault();   

 

Thanks for the reminder, I tested it again, it was me who got the code wrong, thanks

  • Author
On 7/4/2024 at 2:42 PM, Droidz said:

Hello,

string[] objectNames = new string[] { "Bonfire" };
foreach (string objectName in objectNames)
{
    var gameObjects = ObjectManager.GetObjectWoWGameObject()
        .Where(o => o.Name.Contains(objectName) && o.GetDistance <= maxDistance)
        .OrderBy(o => o.GetDistance)
        .FirstOrDefault();

    if (gameObjects != null)
    {
        // ...
    }
}

 

感谢,之前是我自己把代码搞错了,代码能正常使用的,非常感谢

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.