Can someone please tell me how to correct my file saving and import subs? [code]global id global dir$="C:\users\admin\desktop\" if check display mode(1024,768,32)=1 set display mode 1024,768,32 else set display mode 640,480,32 endif sync on : sync rate 0 set ambient light 100 global menu global filenum global filenum2 global filenum3 global file$ start bbb gui `"Media\Ruby.msstyles" windows set font 7,"Arial",0,0,0,0 windows set icon "Media\dbpro_icon.ico" windows set visibility 1 dbpro_w=get dbpro window() : set main window dbpro_w wm1=make window(3,29,210,600,"",dbpro_w, WS_NORMALWINDOW) tab=make tab control(0,0,210,600,TCS_FIXEDWIDTH,wm1) w1=make window(0,22,210,600,"",tab,WS_CHILD) : tab insert item tab,"TAB 1",0,w1 w2=make window(0,22,210,600,"",tab,WS_CHILD) : tab insert item tab,"TAB 2",1,w2 w3=make window(0,22,210,600,"",tab,WS_CHILD) : tab insert item tab,"TAB 3",2,w3 w4=make window(0,22,210,600,"",tab,WS_CHILD) : tab insert item tab,"TAB 4",3,w4 tab set selected item tab,0 tab set item size tab,50,20 `This command creates a button with text b0=make button(20,20,100,20,"button 1",w1) b1=make button(20,20,100,20,"button 2",w2) `This command makes empty menu bar menu=make menu() `File - 1 sub1=make submenu() : menu append submenu menu,sub1,"File" submenu insert item sub1,"New",1 submenu insert separator sub1 submenu insert item sub1,"Open",2 submenu insert item sub1,"Save",3 submenu insert item sub1,"Save As...",4 submenu insert separator sub1 submenu insert item sub1,"Import",5 submenu insert item sub1,"Export",6 submenu insert separator sub1 submenu insert item sub1,"Exit",17 `Edit - 2 sub2=make submenu() : menu append submenu menu,sub2,"Edit" submenu insert item sub2,"Undo",13 submenu insert item sub2,"Redo",14 menu enable item sub2,13,0 sub3=make submenu() submenu insert item sub3,"SubItem1",8 submenu insert item sub3,"SubItem2",9 link submenu sub1,4,sub3 sub4=make submenu() submenu insert item sub4,"SubSubItem1",10 : menu check item sub4,10,1 submenu insert item sub4,"SubSubItem2",11 submenu insert item sub4,"SubSubItem3",12 link submenu sub3,9,sub4 sub5=make submenu(): menu append submenu menu,sub5,"Matrix" submenu insert item sub5,"Create",18 `This command shows rhe menu in our window `NOTE: It is important that this command is called after all ` submenus are added apply menu dbpro_w,menu `Now we will create a popup menu (or context menu) - this is the menu `that pops up when you right click on the screen sub=make submenu() submenu insert item sub,"Item1",1 submenu insert item sub,"Item2",2 submenu insert item sub,"Item3",3 submenu insert item sub,"Item4",4 submenu insert separator sub submenu insert item sub,"Item5",5 submenu insert item sub,"Item6",6 sub5=make submenu() submenu insert item sub5,"SubItem1",7 submenu insert item sub5,"SubItem2",8 submenu insert item sub5,"SubItem3",9 submenu insert item sub5,"SubItem4",10 link submenu sub, 4, sub5 sub6=make submenu() submenu insert item sub6,"SubSubItem1",11 submenu insert item sub6,"SubSubItem2",12 submenu insert item sub6,"SubSubItem3",13 link submenu sub5, 7, sub6 `This commands tells bbb gui plugin that we want this submenu to popup when `right mouse button is clicked show submenu sub, dbpro_w `If you don't want this menu to be shown on right click then put zero as `window handle like this: `show menu sub, 0 set window on string1$=space$(64) string2$=space$(64) global movespeed# as float movespeed#=.2 r#=10 `cam distance CamSpeed#=1 set camera range .1,99999 dim filename$(10000) dim scale#(10000) `***** load objects from editor ******* do position window w,window position x(dbpro_w)+10,window position y(dbpro_w)+50 move camera (keystate(17)-keystate(45))*1 turn camera left (keystate(30)-keystate(32))*1 `Get the id of selected menu item s=MENU GET SELECTED ITEM ID() s2=BUTTON CLICKED(b0) s3=BUTTON CLICKED(b1) if s2 = 1 then end if s3 = 1 then end if s=2 then gosub _load if s=5 then gosub _import if s=18 then inc id: make matrix id,1000,1000,20,20 if s>0 then MENU GET SELECTED ITEM STRING string1$ if s>10 and s<13 menu check radio item menu,11,12,s endif text 20,120,"Last selected menu item string: "+string1$ s=POPUP MENU GET SELECTED ITEM ID() if s>0 then POPUP MENU GET SELECTED ITEM STRING string2$ text 20,140,"Last selected popup menu item string: "+string2$ text 20,160,str$(MENU GET ITEM STATE(Menu, 11)) text 20,180,str$(MENU GET ITEM STATE(sub4, 10)) repeat get event h=event get handle() m=event get message() if h=get main window() if m=WM_CLOSE a=make message box("Exit?","Cyclos",MB_YESNO) if a=IDYES then end bbb gui : end endif endif until m=0 if spacekey() hide mouse position mouse screen width()/2,screen height()/2 else show mouse endif if keystate(29)=1 and keystate(38)=1 then gosub _load if keystate(29)=1 and keystate(24)=1 then gosub _load if keystate(29)=1 and keystate(31)=1 then gosub writedata gosub textguide gosub camera gosub moveobject if filenum2>0 if picked text 10,100,"scale:"+str$(scale#(filenum2)) text 10,140,"Object X:"+str$(object position x(filenum2)) text 10,160,"Object Y:"+str$(object position y(filenum2)) text 10,180,"Object Z:"+str$(object position z(filenum2)) endif endif text 10,200,"filenum2:"+str$(filenum2) sync loop _import: filenum2=1 if file exist (dir$+"level.dat") open to read filenum2,dir$+"level.dat" read file filenum2,numberoftsos read string filenum2,filename$(1) read float filenum2,tsox# read float filenum2,tsoy# read float filenum2,tsoz# read float filenum2,scale#(filenum2) load object filename$(filenum2),filenum2 position object filenum2,tsox#,tsoy#,tsoz# scale object filenum2,100+scale#(filenum2),100+scale#(filenum2),100+scale#(filenum2) text 10,200,"loaded object:"+filename$(filenum2) close file filenum2 else end endif return _load: inc filenum inc filenum2 inc filenum3 file$=getFileName("Select your file^","Music MP3, OGG, MID, MIDI, MOD^*mp3;*.ogg;*.mid;*.midi;*.mod^Image BMP, GIF, JPG^*.bmp;*.gif;*.jpg^3D Models 3DS, DBO, X^*.3ds;*.dbo;*.x^^") if file$<>"" if getFileExtension(file$)="JPG" or getFileExtension(file$)="Jpg" or getFileExtension(file$)="jpg" or getFileExtension(file$)="BMP" or getFileExtension(file$)="Bmp" or getFileExtension(file$)="bmp" or getFileExtension(file$)="PNG" or getFileExtension(file$)="Png" or getFileExtension(file$)="png" for x=1 to 0x3E8 if object exist(x) delete objects 1,x endif next x load image file$,filenum endif endif if file$<>"" if getFileExtension(file$)="3DS" or getFileExtension(file$)="3ds" or getfileExtension(file$)="DBO" or getFileExtension(file$)="dbo" or getFileExtension(file$)="X" or getFileExtension(file$)="x" for x=1 to 0x3E8 if image exist(x) delete image x endif next x while object exist (filenum2)=1 inc filenum2 endwhile repeat get event h=event get handle() m=event get message() if h=get main window() a=make message box("Is this your level?","Cyclos",MB_YESNO) if a=IDYES load object file$,filenum2 position object filenum2,camera position x(),camera position y(),camera position z() yrotate object filenum2,camera angle y() move object filenum2,20 yrotate object filenum2,0 inc objloaded inc numberoftsos exit endif endif until m=0 remstart load object file$,filenum2 if object exist(filenum2) point camera object position x(filenum2),object position y(filenum2),object position z(filenum2) position object filenum2,camera position x(),camera position y(),camera position z() rotate object filenum2,0,0,0 fix object pivot filenum2 endif remend endif endif if file$<>"" if getFileExtension(file$) = "MP3" or getFileExtension(file$)="Mp3" or getFileExtension(file$)="mp3" or getFileExtension(file$)="OGG" or getFileExtension(file$)="Ogg" or getFileExtension(file$)="ogg" or getFileExtension(file$)="MID" or getFileExtension(file$)="Mid" or getFileExtension(file$)="mid" or getFileExtension(file$)="MIDI" or getFileExtension(file$)="Midi" or getFileExtension(file$)="midi" or getFileExtension(file$)="MOD" or getFileExtension(file$)="Mod" or getFileExtension(file$)="mod" load music file$,filenum3 if music playing(filenum3)=1 stop music filenum3 endif if music playing(filenum3)=0 play music filenum3 endif endif else set cursor 10,10 sync print "file not loaded..." sync wait 1000 cls set cursor 10,10 print "Exiting..." sync wait 1000 end endif remstart if file$<>"" if getFileExtension(file$) = "MP3" or getFileExtension(file$)="Mp3" or getFileExtension(file$)="mp3" or getFileExtension(file$)="OGG" or getFileExtension(file$)="Ogg" or getFileExtension(file$)="ogg" or getFileExtension(file$)="MID" or getFileExtension(file$)="Mid" or getFileExtension(file$)="mid" or getFileExtension(file$)="MIDI" or getFileExtension(file$)="Midi" or getFileExtension(file$)="midi" or getFileExtension(file$)="MOD" or getFileExtension(file$)="Mod" or getFileExtension(file$)="mod" load music file$,filenum3 stop music filenum3 if music playing(filenum3)=0 play music filenum3 endif endif else set cursor 10,10 sync print "file not loaded..." sync wait 1000 cls set cursor 10,10 print "Exiting..." sync wait 1000 end endif remend return writedata: filenum2=1 if numberoftsos>0 delete file dir$+"level.dat" open to write filenum2,dir$+"level.dat" write file filenum2,numberoftsos `for filenum2=0 to 1+numberoftsos write string filenum2,filename$(filenum2) write float filenum2,object position x(filenum2) write float filenum2,object position y(filenum2) write float filenum2,object position z(filenum2) write float filenum2,scale#(filenum2) `next object text 0,0,"Data saved" sync wait 1000 else text 0,0,"File not saved. No objects were detected" sync wait 1000 endif return remstart newobject: filenum2=3000001 while object exist (filenum2)=1 inc filenum2 endwhile set cursor 10,10 print "Enter filename of new object: " sync print "" sync input filename$(filenum2) sync load object filename$(filenum2),filenum2 position object filenum2,camera position x(),camera position y(),camera position z() yrotate object filenum2,camera angle y() move object filenum2,20 yrotate object filenum2,0 inc numberoftsos return remend textguide: if texton=0 text 0,0,"Press 'h' for help" if inkey$()="h" then texton=1 endif if texton=1 cls text 0,0,"Press Ctrl+L to load new object" text 0,20,"Press Ctrl+S to save datafile" text 0,40,"Mouse and arrow keys control camera" text 0,80,"When object is selected with left mouse button:-" text 0,100,"Move object by dragging with mouse" text 0,120,"Up and down arrow keys move object up and down" text 0,140,"Left and right arrow keys scale object" text 0,160,"Press "a" to align object to grid" text 0,180,"Press any key to return to editor" text 0,200,"Press Ctrl+O to load a file" sync wait key texton=0 endif return camera: if mouseclick()=0 then ThreeDMoveCam(CamSpeed#) return function ThreeDMoveCam(CamSpeed#) IF CamSpeed# = 0 THEN EXITFUNCTION cam_x# = CAMERA ANGLE X() + MOUSEMOVEY() * movespeed# cam_y# = CAMERA ANGLE Y() + MOUSEMOVEX() * movespeed# cam_z# = CAMERA ANGLE Z() + MOUSEMOVEZ() * movespeed# IF upkey() = 1 polarity=1 MOVE CAMERA CamSpeed# ` XROTATE CAMERA cam_x# ENDIF IF downkey() = 1 polarity=-1 MOVE CAMERA -CamSpeed# ` XROTATE CAMERA cam_x# ENDIF IF leftkey() = 1 position camera camera position x()-(leftkey()+rightkey())*1,camera position y(),camera position z() ` ROTATE CAMERA 0, cam_y#-90, 0 ` MOVE CAMERA CamSpeed# ` ROTATE CAMERA camera angle x(), camera angle y(), 0 ENDIF IF rightkey() = 1 position camera camera position x()-(leftkey()+rightkey())*-1,camera position y(),camera position z() ` ROTATE CAMERA 0, cam_y#+90, 0 ` MOVE CAMERA CamSpeed# ` ROTATE CAMERA camera angle x(), camera angle y(), 0 ENDIF if spacekey() ROTATE CAMERA cam_x#, cam_y#, cam_z# endif endfunction moveobject: if keystate(32) delete object selected endif if picked=0 then filenum2 = pick object(mousex(),mousey(),0,10000) if filenum2>0 and mouseclick()=1 or mouseclick()=2 then hide mouse: picked=1 if picked=1 and mouseclick()=1 if filename$(filenum2)<>"" text 0,20,"Current object: "+filename$(filenum2) text 0,40,"Number of objects: "+str$(numberoftsos) endif recentobject=filenum2 if object exist(filenum2) set object emissive filenum2,rgb(255,255,255) x#=0 y#=0 if upkey()=1 then y#=0.1 if downkey()=1 then y#=-0.1 if leftkey()=1 then x#=-0.1 if rightkey()=1 then x#=0.1 if scale#(filenum2)<1 then scale#(filenum2)=1 if keystate(44) then dec scale#(filenum2) if keystate(45) then inc scale#(filenum2) ang#=object angle y(filenum2) yrotate object filenum2,camera angle y():move object filenum2,-mousemovey() yrotate object filenum2,camera angle y()+90:move object filenum2,mousemovex() yrotate object filenum2,ang# position object filenum2,object position x(filenum2)+x#,object position y(filenum2)+y#,object position z(filenum2) if inkey$()="a" position object filenum2,int(object position x(filenum2)/10)*10,int(object position y(filenum2)/10)*10,int(object position z(filenum2)/10)*10 make object cube 4000001,1 position object 4000001,object position x(filenum2)-100,object position y(filenum2),object position z(filenum2) make object cube 4000002,1 position object 4000002,object position x(filenum2)+100,object position y(filenum2),object position z(filenum2) make object cube 4000003,1 position object 4000003,object position x(filenum2),object position y(filenum2),object position z(filenum2)-100 make object cube 4000004,1 position object 4000004,object position x(filenum2),object position y(filenum2),object position z(filenum2)+100 line object screen x(4000001),object screen y(4000001),object screen x(4000002),object screen y(4000002) line object screen x(4000003),object screen y(4000003),object screen x(4000004),object screen y(4000004) delete object 4000001 delete object 4000002 delete object 4000003 delete object 4000004 endif if scale#(filenum2)>1 scale object filenum2,100+scale#(filenum2),100+scale#(filenum2),100+scale#(filenum2) endif endif else picked = 0 show mouse endif if picked=0 text 0,20,"No object selected" y#=0 if recentobject>0 then set object emissive recentobject,rgb(0,0,0) endif return function get_folder(string$) leng=len(string$) folderlen=leng while done=0 if mid$(string$,c)<>"\" and mid$(string$,c)<>"/" inc folderlen done=1 endif endwhile for c=1 to folderlen folder$=folder$+mid$(string$,c) next endfunction folder$ function get_file(string$) leng=len(string$) folderlen=leng while done=0 if mid$(string$,c)<>"\" and mid$(string$,c)<>"/" dec folderlen done=1 endif endwhile for c=folderlen+1 to leng file$=file$+mid$(string$,c) next endfunction file$ function getFileExtension(name$ as string) length = len(name$) i = length while (mid$(name$, i) <> ".") dec i endwhile ext$ = right$(name$, length - i) endfunction ext$ rem show the file identification dialog function getFileName(FileBoxTitle$,FileFilter$) load dll "user32.dll",1 load dll "kernel32.dll",2 load dll "comdlg32.dll",3 rem Memblock Table OFN_MB = 1 PathBuffer_MB = 2 FileFilter_MB = 3 FileBoxTitle_MB = 4 rem Offset Table OPENFILENAME Struct lStructSize = 0 hwndOwner = 4 hInstance = 8 lpstrFilter = 12 lpstrCustomFilter = 16 nMaxCustFilter = 20 nFilterIndex = 24 lpstrFile = 28 nMaxFile = 32 lpstrFileTitle = 36 nMaxFileTitle = 40 lpstrInitialDir = 44 lpstrTitle = 48 Flags = 52 nFileOffset = 56 nFileExtension = 58 lpstrDefExt = 60 lCustData = 64 lpfnHook = 68 lpTemplateName = 72 StructEnd = 76 rem OPENFILENAME Flag Table OFN_ALLOWMULTISELECT = 512:rem 0x00000200 OFN_CREATEPROMPT = 8192:rem 0x00002000 OFN_ENABLEHOOK = 32:rem 0x00000020 OFN_ENABLETEMPLATE = 64:rem 0x00000040 OFN_ENABLETEMPLATEHANDLE = 128:rem 0x00000080 OFN_EXPLORER = 524288:rem 0x00080000 OFN_EXTENSIONDIFFERENT = 1024:rem 0x00000400 OFN_FILEMUSTEXIST = 4096:rem 0x00001000 OFN_HIDEREADONLY = 4:rem 0x00000004 OFN_LONGNAMES = 2097152:rem 0x00200000 OFN_NOCHANGEDIR = 8:rem 0x00000008 OFN_NODEREFERENCELINKS = 1048576:rem 0x00100000 OFN_NOLONGNAMES = 262144:rem 0x00040000 OFN_NONETWORKBUTTON = 131072:rem 0x00020000 OFN_NOREADONLYRETURN = 32768:rem 0x00008000 OFN_NOTESTFILECREATE = 65536:rem 0x00010000 OFN_NOVALIDATE = 256:rem 0x00000100 OFN_OVERWRITEPROMPT = 2:rem 0x00000002 OFN_PATHMUSTEXIST = 2048:rem 0x00000800 OFN_READONLY = 1:rem 0x00000001 OFN_SHAREAWARE = 16384:rem 0x00004000 OFN_SHOWHELP = 16:rem 0x00000010 rem FileBox Info FileBoxFlags = OFN_EXPLORER + OFN_FILEMUSTEXIST + OFN_PATHMUSTEXIST + OFN_LONGNAMES + OFN_HIDEREADONLY + OFN_NONETWORKBUTTON PathBufferSize = 256 hWnd = call dll(1,"GetActiveWindow") hMod = call dll(2,"GetModuleHandleA",0) rem Create Memblock Struct make memblock OFN_MB,StructEnd make memblock PathBuffer_MB,PathBufferSize make memblock FileFilter_MB,len(FileFilter$) make memblock FileBoxTitle_MB,len(FileBoxTitle$) OFN = get memblock ptr(OFN_MB) PathBuffer = get memblock ptr(PathBuffer_MB) FileFilter = get memblock ptr(FileFilter_MB) FileBoxTitle = get memblock ptr(FileBoxTitle_MB) rem Dump Strings to Memblock dump(FileFilter_MB,FileFilter$) dump(FileBoxTitle_MB,FileBoxTitle$) rem Write to OPENFILENAME Struct write memblock dword OFN_MB,lStructSize,StructEnd write memblock dword OFN_MB,hWndOwner,hWnd write memblock dword OFN_MB,hInstance,hMod write memblock dword OFN_MB,lpstrFilter,FileFilter write memblock dword OFN_MB,lpstrFile,PathBuffer write memblock dword OFN_MB,nMaxFile,PathBufferSize write memblock dword OFN_MB,Flags,FileBoxFlags write memblock dword OFN_MB,lpstrTitle,FileBoxTitle rem Open FileBox call dll 3,"GetOpenFileNameA",OFN result$ = getstr(PathBuffer_MB) rem Delete Memblock Struct delete memblock OFN_MB delete memblock PathBuffer_MB delete memblock FileFilter_MB delete memblock FileBoxTitle_MB delete dll 1 delete dll 2 delete dll 3 endfunction result$ rem fonctions utilisées pour l'identification d'une fichier function dump(m,s$) for p=1 to len(s$) b=asc(mid$(s$,p)) if b=asc("^") then b=0 write memblock byte m,p-1,b next p endfunction function getstr(m) p=0:s$="" do b=memblock byte(m,p) if b=0 then exit s$=s$+chr$(b) inc p loop endfunction s$[/code] This post is from -- http://socoder.net/index.php?topic=1979