Hey guys!
I came across this very strange bug and thought I'd share it with you. I'm working on a level editor, and when you load a file in the editor it will copy the file you selected to a local folder and then load it from there. What happened was the objects you wanted to load loaded
with textures (they shouldn't because the textures aren't in the same folder), and some of the limbs from the object were missing. If I deleted and re-loaded the object, it would work, but it was still textured.
So I wanted to get to the bottom of this. Here is the code I used, which is extracted from my level editor and dumbed down a bit. You'll need to download the attached project folder to load the object.
rem strange monkey business with copy file
rem by TheComet
rem setup screen
sync on
sync rate 60
backdrop on
color backdrop 0x808080
hide mouse
disable escapekey
#constant LoadOriginal 1
rem load original object
if LoadOriginal = 1
load object "original\bla.x" , 1
set object transparency 1 , 2
endif
rem main loop
repeat
rem screen fps
text 0 , 0 , "Screen FPS : " + str$( screen fps() )
text 0 , 20 , "Original Object - Press <return> to continue"
rem rotate camera
inc height# , mousemovey() * 0.6
angle# = wrapvalue( angle# + ( mousemovex() * 0.6 ) )
set camera to follow 0 , 0 , 0 , angle# , 20 , height# , 2 , 0
point camera 0 , 0 , 0
rem refresh screen
sync
rem end of main loop
until returnkey() or LoadOriginal = 0
repeat:until returnkey()=0
rem delete object
if object exist(1) then delete object 1
rem create project folder
OriginalDirectory$ = get dir$()
if path exist("copy")=0 then make directory "copy"
set dir "original"
filename$ = OriginalDirectory$ + "\original\bla.x"
rem create xyz lines
make object plain 1 , 0 , 10000 : color object 1 , 0xFF00FF00 : set object wireframe 1 , 1
make object plain 2 , 0 , 10000 : xrotate object 2 , 90 : color object 2 , 0xFF0080FF : set object wireframe 2 , 1
make object plain 3 , 0 , 10000 : zrotate object 3 , 90 : color object 3 , 0xFFFF0000 : set object wireframe 3 , 1
rem create center camera object
make object sphere 4 , 4
set object wireframe 4 , 1
set object cull 4 , 0
rem copy file across
if file exist(OriginalDirectory$+"\copy\" + GetFileName(filename$)) then delete file OriginalDirectory$+"\copy\" + GetFileName(filename$)
copy file filename$ , OriginalDirectory$+"\copy\" + GetFileName(filename$)
filename$ = OriginalDirectory$+"\copy\" + GetFileName(filename$)
rem load the object
load object filename$ , 5
set object transparency 5 , 2
rem main loop
repeat
rem screen fps
text 0 , 0 , "Screen FPS : " + str$( screen fps() )
text 0 , 20 , "Copied object"
rem rotate camera
inc height# , mousemovey() * 0.6
angle# = wrapvalue( angle# + ( mousemovex() * 0.6 ) )
set camera to follow 0 , 0 , 0 , angle# , 20 , height# , 2 , 0
point camera 0 , 0 , 0
rem refresh screen
sync
rem end of main loop
until escapekey()
rem clean up
set dir OriginalDirectory$
delete object 5
delete file "copy\bla.x"
delete directory "copy"
rem end
end
function GetFileName(name$ as string)
rem local variables
local n as integer
rem scan until backslash is found
for n = 0 to len(name$)
if left$(right$(name$,n),1) = "\" then exit
next n
rem return name
name$ = right$(name$,n-1)
endfunction name$
So why does the object load with textures?
The reason is because the directory is still set to where the textures are located using
set dir. If you add the line
set dir OriginalDirectory$ just before you load the object, it won't be textured.
Why are some limbs missing?
They aren't missing, they are just black. And because I used
set object transparency obj , 2, they are completely transparent.
Why are some limbs black and other white? I have no idea...
TheComet