Skip to content

public bool TryFindByCode(ulong code, out DwarfAbbreviationItem item) failed #28

Open

Description

@Albert-Coder

in DwarfAbbreviation.cs line 87;

   `public bool TryFindByCode(ulong code, out DwarfAbbreviationItem item)
    {
        item = null;
        if (code == 0)
        {
            return `false;
        }

        code--;

        if (_mapItems.Count > 0)
        {
            return _mapItems.TryGetValue(code, out item);
        }

        if (code < int.MaxValue && (int)code < _items.Count)
        {
            item = _items[(int) code];
            return true;
        }

        item = null;
        return false;
    }`

I found sometimes it failed at return _mapItems.TryGetValue(code, out item);
Then I fixed below; I do not konw if you have the same problem;

    `public` bool TryFindByCode(ulong code, out DwarfAbbreviationItem item)
    {
        item = null;
        if (code == 0)
        {
            return false;
        }

        //no need to minus 1
        //code--;

        if (_mapItems.Count > 0)
        {
            return _mapItems.TryGetValue(code, out item);
        }

        //if _mapItems is empty, try _items;
        if (code < int.MaxValue && (int)code <= _items.Count)
        {
            item = _items[(int) code - 1];
            return true;
        }

        item = null;
        return false;
    }

Activity

  1. added
    bugSomething isn't working
    Help WelcomeA pull-request is welcome to fix this issue
    on Oct 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Help WelcomeA pull-request is welcome to fix this issuebugSomething isn't working

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions