im trying to...

Blitz3D Forums/Blitz3D Beginners Area/im trying to...

Apollonius(Posted 2003) [#1]
Well I'm trying to do this:
if newfile is clicked (value 1)
then if filein doesnt exist create temp.dat
else
delete temp.dat
and create temp.dat
closefile

How should I do it?
this shouldnt be to hard im guessing


  If newfile = 1 Then
	  
	  If Not ReadFile (filein) = 0 Then
	      filein = WriteFile("temp.dat")
	     CloseFile( filein )
	    newfile = 0
	  EndIf
	
	
	EndIf



ford escort(Posted 2003) [#2]
easy :)
if newfile=1
    if filetype("temp.dat")=0 ;-----if file doesnt exits
       filein=writefile("temp.dat") ;create the file
       closefile(filein)
    else ;--------------------------else
       deletefile("temp.dat") ;-----delete the file
       filein=writefile("temp.dat") ;create the file
       closefile(filein)
    endif
endif



eBusiness(Posted 2003) [#3]
Hmmm, think your description will only work if filein$ = "temp.dat", or at least either both or none of them should exist. what exacly do you want to do? Got four options, depending on wich of the two files exist.


Neo Genesis10(Posted 2003) [#4]
Ford, your quotation marks are a little on the screwy side :)


ford escort(Posted 2003) [#5]
yeah let me try again without the screwy quotations ^-^ and with a more generic function :)

if newfile=1
   makefile("","temp.dat")
endif
;
;
;
;
function makefile(directory$,filename$)
   if filetype(directory$+filename$)=0         
      filein=writefile(directory$+filename$) 
      closefile(filein)
   else
       deletefile(directory$+filename$)   
       filein=writefile(directory$+filename$) 
       closefile(filein)
    endif
end function



Apollonius(Posted 2003) [#6]
fonction can only appear in the main program?
what does that mean?

....

Global newfile = 0

Repeat

.....

	; NEW FILE
	If newfile=1
   makefile("","temp.dat")
     newfile=0
EndIf


;-----------------------
; FONCTIONS
;-----------------------


Function makefile(directory$,filename$)
   If FileType(directory$+filename$)=0         
      filein=WriteFile(directory$+filename$) 
      CloseFile(filein)
   Else
       DeleteFile(directory$+filename$)   
       filein=WriteFile(directory$+filename$) 
       CloseFile(filein)
    EndIf
End Function



Forever
End



Apollonius(Posted 2003) [#7]
not in the loop... riiiighhht