Hello! I'm having a nightmare with this code that is designed to search for files. I've posted the whole module, as it is part of an rts. It's very highly commented, but if you look at this bit:
repeat
rem store the file in the files$ array
files$( find_free_file() ) = get file name$()
rem find the next file/folder
find next
text 0,0, files$( 1000 )
rem repeat until there is no more files - hence file type = -1
until get file type() = -1
It is stuck in that loop somehow! It just keeps writing the same values to the array. There is only one item in the folder, which is "Britain".
files$(1) is equal to .
files$(2) is equal to ..
files$(3) is equal to Britain
then it repeats all the way to 1000
Surely it should report an error that the data of the file i want doesn't exist?
Or am i using the wrong method to detect the end of the directory?
Any help would be appreciated.
thanks
full code:
rem make an array to hold the contents of the current directory
dim files$(1000)
rem make an array to hold the contents of the .ent files found
dim entities$(1000)
rem make an array to hold the path of each folder that has already been scanned
dim path$(1000)
rem this variable holds the amount of levels the search has gone down
down as integer
rem set the directory to the entities folder
set dir "Assets\Entities"
repeat
rem find the first file/folder in the directory
find first
repeat
rem store the file in the files$ array
files$( find_free_file() ) = get file name$()
rem find the next file/folder
find next
text 0,0, files$( 1000 )
rem repeat until there is no more files - hence file type = -1
until get file type() = -1
rem loop through the files$
for i = 3 to 1000
rem if the last 4 letters of the file name = .ent then add it to the entities$ array
if right$( files$( i ), 4 ) = ".ent"
entities$( find_free_entities() ) = files$( i )
endif
next i
rem add the directory to the scanned list
path$( find_free_path() ) = get dir$()
rem loop through the files$ again
for i = 3 to 1000
rem if there is an entry for the array
if files$( i ) <> ""
rem if the path exists
if path exist ( files$( i ) ) = 1
rem but the file doesn't, then it must be a folder
if file exist( files$( i ) ) = 0
rem loop through the list of directories already scanned
for o = 1 to 1000
rem if the directory of the proposed is in the list of already scanned
if get dir$() + "\" + files$ = path$( o )
rem set temp variable to 1, meaning to skip this directory
tempvariable = 1
endif
next o
rem if the directory has not been scanned
if tempvariable = 0
rem set the new directory
set dir get dir$() +"\"+ files$
rem add one layer down
down = down + 1
rem exit the loop
exit
endif
rem if the files does exist
else
rem if it's the last item
if i = 1000
rem go up one level, if possible
if down > 0
rem reduce the down variable
down = down - 1
rem set the directory to the level above
set dir get dir$() + "\.."
else
done = 1
endif
endif
endif
rem if there is no entry
else
rem go up one level, if possible
if down > 0
rem reduce the down variable
down = down - 1
rem set the directory to the level above
set dir get dir$() + "\.."
else
done = 1
endif
endif
endif
next i
sync
until done = 1
rem this function finds an unused slot in the files$ array
function find_free_file()
for i = 1 to 1000
if files$( i ) = ""
returnvar = i
exit
endif
next i
endfunction returnvar
rem this function finds an unused slot in the entities$ array
function find_free_entities()
for i = 1 to 1000
if entities$( i ) = ""
returnvar = i
exit
endif
next i
endfunction returnvar
rem this function finds an unused slot in the path$ array
function find_free_path()
for i = 1 to 1000
if path$( i ) = ""
returnvar = i
exit
endif
next i
endfunction returnvar
rem this function clears the files$ array
function clear_files_array()
for i = 1 to 1000
files$( i ) = ""
next i
endfunction
EDIT: It would seem the problem isn't what I thought it was, I forgot to take into account that the
sync was outside that loop. I've forgotton to clear the array out. Sorry for making a pointless post.