Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Discussion / write file problem

Author
Message
gp_ua
19
Years of Service
User Offline
Joined: 29th Mar 2007
Location:
Posted: 30th Mar 2007 03:10
I've made a high score system for my game that checks to see if there is a file named "high_scores.txt," and if not, then creates it. This works fine within the Dark BASIC editor, but when I create a final executable, it does not write the file, and then it tries to access a file that doesn't exist and freezes my computer. What the heck is happening?

[
if file exist("high_scores.txt")
py=1
else
open to write 1,"high_scores.txt"
write string 1,"8000"
write string 1,"7500"
write string 1,"7000"
write string 1,"6500"
write string 1,"6000"
write string 1,"5000"
write string 1,"4000"
write string 1,"3000"
write string 1,"2000"
write string 1,"1000"

rem write a -1 to separate names and scores for parsing
write string 1,"-1"

rem write names
write string 1,"JSD"
write string 1,"JSD"
write string 1,"JSD"
write string 1,"JSD"
write string 1,"JSD"
write string 1,"JSD"
write string 1,"JSD"
write string 1,"JSD"
write string 1,"JSD"
write string 1,"JSD"

rem we're done writing so close it
close file 1
endif
]

Does anyone know what's happening with this?
Quisco DaLuse
19
Years of Service
User Offline
Joined: 3rd Feb 2007
Location: USA
Posted: 30th Mar 2007 16:03
I copied the code you have listed into the DB editor and ran it and re-ran it and it worked fine. The file was written exactly as you intended. I don't see anything in this code that is going to cause your computer to lock up.

You idiots! You've captured their stunt doubles!
gp_ua
19
Years of Service
User Offline
Joined: 29th Mar 2007
Location:
Posted: 30th Mar 2007 16:28
The code I included is only the writing portion of the code, and it does work just fine - but only in the editor. The problem is that it will not write out once I have compiled it into a final executable file, and therefore the other part of the code, which I have not included, tries to access the nonexistent file and freezes, a problem which I have remedied, though not to the satisfaction of the former, which puzzles me still.

I know nothing about the workings of executables, but there seems to be something keeping them from writing out. I've copied my code above into a single executable and it does not write out. I can't figure it out.
Van B
Moderator
23
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sunnyvale
Posted: 30th Mar 2007 16:41
Just wondering, but your not using Vista are you?

The only other thing that I think could cause problems is looking in the wrong place, like if you set the directory to something, always put in a SET DIR ".." at the end to get back to your last directory.


Good guy, Good guy, Wan...
gp_ua
19
Years of Service
User Offline
Joined: 29th Mar 2007
Location:
Posted: 30th Mar 2007 17:09
Hey, thanks so much Van, the set directory command somehow made it work. I never set the directory to anything, believing that it automatically looked in whatever directory the executable was presently in, but it works now anyhow. This is actually an assignment for a game class, and it is due today. You saved my bacon.
TDK
Retired Moderator
23
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 2nd Apr 2007 15:24
Quote: "The only other thing that I think could cause problems is looking in the wrong place, like if you set the directory to something, always put in a SET DIR ".." at the end to get back to your last directory."


100% correct - as usual!

Another way (that I use) is to put:

StartDir$ = Get Dir$()+"\"

at the very start of my program. From then on, if I have to access any files, I use something like:

StartDir$+"Filename.ext"

This is particularly useful if you have subdirectories. For example if your above highscore file was in a folder called 'Data' you would simply use:

Open To Write 1,StartDir$+"\Data\High_scores.txt"

Other files can be accessed in other directories by using exactly the same thing, but simply changing 'Data' to the correct folder name - and of course the filename.

TDK_Man

Login to post a reply

Server time is: 2026-07-05 18:39:07
Your offset time is: 2026-07-05 18:39:07