With DarkMatter 2 you get the source to a simple model browser. I wanted to edit it to load some models I've been working on. When I tried to run the edited source I got an error, which I assumed was because of a change I had made. After failing to see what I could have done to cause the error I just tried to compile the unedited source to see if it would work. It didn't it still gave the same error which is "Runtime Error 118 - Array does exist or array subscript out of bounds at Line 15"
Here is the unedited code:
rem Mega-Simple Auto-List Browser
rem Init app
sync on : sync rate 60 : hide mouse : color backdrop rgb(64,64,64)
rem Create list
dim list$(0) : empty array list$()
scandir("Media","")
listmax=2+array count(list$())
listtop=1
rem Show filename only
dim showlist$(listmax)
for i=0 to listmax
file$=list$(i)
for n=len(list$(i)) to 1 step -1
if mid$(list$(i),n)="\" or mid$(list$(i),n)="/"
file$=right$(file$,len(file$)-n) : exit
endif
next n
showlist$(i)=file$
next i
rem Current vars
highlight=1 : loadobject=1
rem Load logo image and Setup font
set image colorkey 64,64,64 : load image "logo.bmp",1
set text font "Courier New"
set text transparent
rem Main loop
do
rem Control interface
if scancode()=0 then keypress=0
if keypress=0
if upkey()=1 and highlight>1 then dec highlight : keypress=1
if downkey()=1 and highlight<listmax-1 then inc highlight : keypress=1
endif
if highlight>listtop+displaymax then listtop=highlight-displaymax
if highlight<listtop then listtop=highlight
if spacekey()=1 then loadobject=highlight
if object exist(1)=1
if leftkey()=1 then yrotate object 1,wrapvalue(object angle y(1)-1)
if rightkey()=1 then yrotate object 1,wrapvalue(object angle y(1)+1)
if returnkey()=1 then stop object 1 : set object frame 1,0
if inkey$()="," and camera position z()<0 then move camera zoomspeed#
if inkey$()="." then move camera zoomspeed#*-1.0
endif
rem Load model
if loadobject<>-1
object$=list$(loadobject-1) : gosub _loadmodel
loadobject=-1
endif
rem Refresh interface
gosub _refreshscreen
rem Update screen
sync
rem End loop
loop
_refreshscreen:
rem display settings
gap=20
topline=80
filewidth=200
displaymax=22
displaywidthmax=30
rem Draw text
set text size 16
ink rgb(255,255,255),0
sprite 1,320-128,1,1 : size sprite 1,256,50
center text 320,430,"[UP]+[DOWN] : NAVIGATE [SPACE] : LOAD MODEL [<]+[>] : ZOOM IN AND OUT"
center text 320,450,"[LEFT]+[RIGHT] : ROTATE MODEL [RETURN] : RESET ANIMATION"
text gap,50,"FILE : "+thisfile$
text gap+gap+filewidth,50,"PATH : "+thispath$
rem List File Selection
set text size 14
for n=0 to displaymax
if listtop+n<listmax
if listtop+n=highlight
ink rgb(255,255,255),0
else
ink 0x3FFFFFFF,0
endif
text gap,topline+6+(n*14),right$(showlist$(listtop+n-1),displaywidthmax)
endif
next n
return
_loadmodel:
rem Delete any existing objects
if object exist(1)=1 then delete object 1
rem Load object
load object "media\"+object$,1
rem Override some properties of the object
set object diffuse 1,rgb(255,255,255)
set object specular 1,0
rem Standard conversion for DM2 object use
xrotate object 1,270
fix object pivot 1
rem Good first view
rotate object 1,0,180+45,0
rem Standard model animation speed
loop object 1 : set object speed 1,6400
rem Move camera up by object height
h#=object size z(1)/2.0
zoomspeed#=object size y(1)/10.0
w#=(object size x(1)+object size y(1))/4.0
position camera camera position x()-(w#/2),camera position y()+h#,camera position z()
rem If Z axis is very small, give camera a jolt
if object size z(1)<w# then move camera w#*-2
rem Set light for view
set light range 0,10000
set point light 0,camera position x(),camera position y(),camera position z()
rem Ensure scale of object data does not affect its lighting
set normalization on
rem get file from filename
thisfile$=object$
for n=len(object$) to 1 step -1
if mid$(object$,n)="\" or mid$(object$,n)="/"
thisfile$=right$(thisfile$,len(thisfile$)-n)
exit
endif
next n
rem get path from filename
thispath$=left$(object$,n)
return
`
` Function to scan for files
`
function scandir(folder$,rel$)
`
set dir folder$
find first : fin=0
while get file type()>-1
file$=get file name$()
if file$="." or file$=".."
rem ignore . and ..
else
if get file type()=1
scandir(file$,rel$+file$+"\")
find first
if fin>0
for t=1 to fin : find next : next t
endif
else
if lower$(right$(file$,2))=".x"
array insert at bottom list$()
list$()=rel$+file$
endif
endif
endif
find next
fin=fin+1
endwhile
set dir ".."
`
endfunction
Line 15 is the one which says "file$=list$(i)".
Anyway I have tried to fix this error but I just can't. If anybody could explain to me what the problem is, it would be greatly appreciated.
[center]