forums

TNT Basic Forums > Programming Q&A
Creating a file
< Last Thread     Next Thread >
Author
Thread        Post A Reply

10-30-2002 04:49

Posted by:
Jamie

Find more posts by Jamie

I am using this code to try to create a file:

Procedure Save()
int file
Set directory user preferences
file=create file("ppsave","TEXT","Text")
file write file,currentlevel
file write file,lives
file write file,packpower
file write file,score

end proc

But everytime I call the procedure it bombs out and tells me file could not be written. But when I check my preferences folder a file is there with the correct name, but it is not a text file. It just has a blank icon and when I double click it it either asks me to open Adobe Illustrator (!?) or one time it lauched my game instead.

Is my code wrong and if so, can anyone help?

Thanks
Jamie

10-31-2002 05:03

Posted by:
Holmes

Click Here to Email Holmes   Find more posts by Holmes

I think I found your problem. Your program would try to create the file regardless of wether it exists or not already. Try putting this in your function:

Set directory user preferences
if not (File Exists( "ppsave" ))
int fp=create file("ppsave","TEXT","Text")
else
int fp=open file("ppsave",true,"TEXT")
end if
file write fp,currentlevel
file write fp,lives
file write fp,packpower
file write fp,score
close file fp

This is just a modified version that will just open the file if it already exists.

10-31-2002 18:15

Posted by:
Jamie

Find more posts by Jamie

Thanks Holmes, that pretty much did it. I had to make one small change to your second 'int' statement.

int fp=open file("ppsave",true,"TEXT","Text")

Had to add the "Text" file type, but then it worked fine.

Thanks!

10-31-2002 22:42

Posted by:
Holmes

Click Here to Email Holmes   Find more posts by Holmes

No prob, I actually responded and worked with your code because I needed a better understanding as well.

All times are GMT        Post A Reply

Forum Jump:
< Last Thread     Next Thread >

< Contact Us - TNT Basic >

Powered by: vBulletin Lite Version 1.0.1 Lite
Copyright © Jelsoft Enterprises Limited 2000.