i=CurrentFile() .....gives back the number of the file currently in use.
i=0 if no file is in use.
With this you could open/close/... files everywhere without having to track
files in use, e.g.:
Procedure abc()
i=CurrentFile()
OpenFile(...)
...do something
CloseFile()
If i<>0: UseFile(i): Endif
EndProcedure
.../tomio
CurrentFile()
- Fou-Lu
- Enthusiast
- Posts: 201
- Joined: Tue Jul 12, 2005 8:30 am
- Location: I'm pretty sure this is all a nightmare
- Contact:
Why don't you do like that:
I know it would be easier with "currentfile()" but it's not that necessary.
By the way:
Code: Select all
Global currentfile.l
procedure blah()
openfile(x) ;you will probably know which file you are going to open
currentfile=x ;just keep its number in a variable
...
closefile(x)
if currentfile<>0:usefile(currentfile):endif
EndProcedure
By the way:
You can load a #0 file.Tomio wrote:i=CurrentFile() .....gives back the number of the file currently in use.
i=0 if no file is in use.
Code: Select all
OpenFile(0,"myfile.bla")
- Fou-Lu
- Enthusiast
- Posts: 201
- Joined: Tue Jul 12, 2005 8:30 am
- Location: I'm pretty sure this is all a nightmare
- Contact:
Sorry for double posting.
Now I realize exactly what you meant in your procedure. So, before you start complaining I didn't understand, here's another code as an example:
Indeed, it would be annoying to get the file number every time you open a new file, mainly if your code is already too long and you have to change it... Alright, I agree, CurrentFile() could be useful. 

Code: Select all
Global currentfile.l
procedure abc() ;abc as you named it :)
OpenFile(...)
...do something
CloseFile()
If currentfile=>0: UseFile(currentfile): Endif ;you should get current file before hand or use as a parameter in the procedure.
EndProcedure
... two hundred thousand lines of code
openfile(a) ;Oops, you opened a file, get its number
currentfile=a
... more code
DisplaySprite(0,x,y)
DisplayPaletteSprite(1,x,y,2) ; this doesn't exist yet...
abc() ; after "abc", current file should be the same.
