AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   dupes in read_dir (https://forums.alliedmods.net/showthread.php?t=2746)

jtp10181 06-15-2004 18:02

dupes in read_dir
 
Code:
    while(read_dir("maps",numword,data,63,temp)) {         if((contain(data,".bsp") != -1) && (containi(data,".ztmp") == -1)) {             if(totalmaps >= MAX_MAPS){                 server_print("[AMXX] MAX_MAPS has been exceeded, not all maps are able to load for searching")                 return PLUGIN_HANDLED             }             copy(T_LMaps[totalmaps],31, data)             replace(T_LMaps[totalmaps],31,".bsp","")             totalmaps++         }         numword++     }

this is producing dupes in the array, usually like 10 of each map. One time I noticed the first map was duped 4 times and then after that the rest were 8 times. Really strange. I ONLY is doing this on linux systems as far as I know, have not seen it occur in windows.

Also does anyone have some code I could borrow/look at for sorting an array?

PM 06-16-2004 14:01

hmm well: read_dir has a completly different implementation on GCC (thats our standard linux compiler) and on MSVC (our standard windows compiler). Ill check it.

Sorting an array: The probably simpliest (and slowest ;) ) way is bubble sort. The theory is something like this:
Code:

for (i=0;i<max;++i)
{
  for(j=0;j<max;++j)
  {
      if ([ element j+1 < j ])
      {
        [ swap j and j+1 ]
      }
  }
}

I think 8)

jtp10181 06-16-2004 14:06

yeah i got the sorting worked out

http://forums.alliedmods.net/showthread.php?t=2756

as foir the dupes I added a little check to see if the last thing loaded is the same as the current and to just skip it. should fix the problem for now I hope.

jtp10181 06-16-2004 14:32

I just tried my little thing to look back and skip if its a dupe on a server with 375 maps and it hung for like a full minute when the server started.... i think the number of dupes that it pulls in just keeps growing and growing on linux, it works fine in windows still BTW

PM 10-17-2004 11:07

Re: dupes in read_dir
 
Try this:

Code:
       while(numword = read_dir("maps",numword,data,63,temp)) {         if((contain(data,".bsp") != -1) && (containi(data,".ztmp") == -1)) {             if(totalmaps >= MAX_MAPS){                 server_print("[AMXX] MAX_MAPS has been exceeded, not all maps are able to load for searching")                 return PLUGIN_HANDLED             }             copy(T_LMaps[totalmaps],31, data)             replace(T_LMaps[totalmaps],31,".bsp","")             totalmaps++         }     }
You get the idea; let read_dir return the number identifying the next entry instead of incrementing on your own.

jtp10181 10-17-2004 11:20

omfg I'm dumb.... that works. I think I wrote that code when I was a nub and never noticed how dumb that was

PM 10-17-2004 11:22

Quote:

Originally Posted by jtp10181
omfg I'm dumb.... that works. I think I wrote that code when I was a nub and never noticed how dumb that was

Heh I haven't noticed it in your code either.. I'm blind ;)


All times are GMT -4. The time now is 14:50.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.