Page 1 of 1
CurrentFile()
Posted: Thu Aug 04, 2005 9:27 pm
by Tomio
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
Posted: Fri Aug 05, 2005 4:59 am
by Fou-Lu
Why don't you do like that:
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
I know it would be easier with "currentfile()" but it's not that necessary.
By the way:
Tomio wrote:i=CurrentFile() .....gives back the number of the file currently in use.
i=0 if no file is in use.
You
can load a #0 file.
Posted: Fri Aug 05, 2005 5:20 am
by Fou-Lu
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:
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.
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.

Posted: Sun Aug 07, 2005 9:00 pm
by Tomio
Fou-Lu wrote:... Alright, I agree, CurrentFile() could be useful.

Thanks Fou-Lu for the assistance!
../tomio
Posted: Sun Aug 07, 2005 11:00 pm
by Fred
I think than all current things will disappear with the next major release of PB, so a such command will probably never happen.