.:: Bots United ::.

.:: Bots United ::. (http://forums.bots-united.com/index.php)
-   General Bot Coding (http://forums.bots-united.com/forumdisplay.php?f=24)
-   -   Important! :P Player Model Search bug fix (http://forums.bots-united.com/showthread.php?t=1863)

Cheeseh 04-06-2004 00:39

Important! :P Player Model Search bug fix
 
Heya

I've been having trouble with my bots not adding ALL of the available player models to their list of available models to select.

I found a "bug" in the FindDirectory code of good ol' botman's directory searching I used from HPB_bot code.

The bug is that it kept skipping some directories with me, and did not work as expected.

this
Code:

      while ( pFindFileData.dwFileAttributes != FILE_ATTRIBUTE_DIRECTORY )
      {
        if (FindNextFile(hFile, &pFindFileData) == 0)
        {
            FindClose(hFile);
            hFile = NULL;
            return hFile;
        }       
      }

should be this
Code:

      while ( (pFindFileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != FILE_ATTRIBUTE_DIRECTORY )
      {
        if (FindNextFile(hFile, &pFindFileData) == 0)
        {
            FindClose(hFile);
            hFile = NULL;
            return hFile;
        }       
      }

it didn't take into account that a directory could have several more flags set on it (e.g. Read only/Archived etc)

ps you need to update two of these in the FindDirectory() function...


(w00t) 8D

Pierre-Marie Baty 04-06-2004 02:11

Re: Important! :P Player Model Search bug fix
 
Thanks!
That's been marked to be put into the next HPB_bot update (if ever there is one...) :)

Austin 04-06-2004 09:43

Re: Important! :P Player Model Search bug fix
 
Quote:

Originally Posted by Cheeseh
Heya
I found a "bug" in the FindDirectory code of good ol' botman's directory searching I used from HPB_bot code.

should be this
Code:

while ( (pFindFileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != FILE_ATTRIBUTE_DIRECTORY )

Well.. not quite..
It MAY work but this would be by-chance.

dwFileAttributes is a bit mask and we are testing for the bit
FILE_ATTRIBUTE_DIRECTORY,

Thus we AND them but then TEST FOR 0 OR NON 0.

if (!(fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY))
//code looking for files go here..

if ((fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY))
// code looking for dirs go here..

>edit<
Yup, yup, you guys are correct.
Either way will work, but if you want to use positive logic you have to do it your way.

Pierre-Marie Baty 04-06-2004 14:10

Re: Important! :P Player Model Search bug fix
 
Actually Austin...
Code:

while ( (pFindFileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != FILE_ATTRIBUTE_DIRECTORY )
is the exact equivalent to
Code:

while (!(pFindFileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY))
so Cheeseh's code WILL work after all... :)

Cheeseh 05-06-2004 12:27

Re: Important! :P Player Model Search bug fix
 
Yup. When you use bitwise operators you don't get a boolean, you get the resulting bitmask. It just so happens that the resulting bit mask is also a number :P And if the one thing you were testing it against was found then it should equal the same thing.


All times are GMT +2. The time now is 10:12.

Powered by vBulletin® Version 3.8.2
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.