
-----------------------------------
tjmoore1993
Wed Apr 01, 2009 7:27 pm

[HELP] saving / loading system minor issue
-----------------------------------
I'm making this game and I've stumbled across a problem because I want to make the program bullet-proof.
I've looked into the problem and I do not know how to code it.

What I want to do is when my program is loading a file and the file is there it loads, but of course I got this working.
The problem is when the file isn't there the program crashes. How would I make it so that the program gives some sort of an error
and says something like please relocate the file or make sure it is in the proper directory.

elsif sav_option = "2" then
    put "What is the name of your saved file?"
    get file_name
    file_name += extension
    location += file_name
    open : stream, location, get
    loop
        exit when eof (stream)
        get : stream, char_name
        get : stream, char_sex
        get : stream, char_job
        get : stream, a_point
        get : stream, h_point
        get : stream, m_point
        get : stream, s_point
        get : stream, d_point
        get : stream, i_point
        get : stream, l_point
    end loop
    close : stream
else
    put "There is a problem locating the saved file."
end if


Mod Edit: Remember to use syntax tags! Thanks :) Code Here

-----------------------------------
saltpro15
Wed Apr 01, 2009 7:30 pm

RE:[HELP] saving / loading system minor issue
-----------------------------------
I don't think you can, Turing can't handle that kind of thing, if this is a class project your teacher should overlook minor errors like that

-----------------------------------
tjmoore1993
Wed Apr 01, 2009 7:42 pm

RE:[HELP] saving / loading system minor issue
-----------------------------------
This is a personal project and I am trying to push turing to its limits.

-----------------------------------
Warchamp7
Wed Apr 01, 2009 8:02 pm

RE:[HELP] saving / loading system minor issue
-----------------------------------
I'm not 100% on the matter but try this


elsif sav_option = "2" then
put "What is the name of your saved file?"
get file_name
file_name += extension
location += file_name 
if stream > 0 then
open : stream, location, get
loop
exit when eof (stream)
get : stream, char_name
get : stream, char_sex
get : stream, char_job
get : stream, a_point
get : stream, h_point
get : stream, m_point
get : stream, s_point
get : stream, d_point
get : stream, i_point
get : stream, l_point
end loop
close : stream 
else
put "There is a problem locating the saved file."
end if

-----------------------------------
Dusk Eagle
Wed Apr 01, 2009 8:34 pm

Re: [HELP] saving / loading system minor issue
-----------------------------------
You most definitely can do that!


loop
    put "What is the name of your saved file?"
    get file_name %In this example, the user must enter the extension themself.
    exit when File.Exists(file_name)
    put "Unavailable file. Please try again."
end loop
open: file, file_name


-----------------------------------
tjmoore1993
Thu Apr 02, 2009 12:21 pm

RE:[HELP] saving / loading system minor issue
-----------------------------------
Thanks for the help I came up with this solution.

        elsif sav_option = "2" then
            loop
                cls
                put "What is the name of your saved file?"
                get file_name
                file_name += extension
                location += file_name
                exit
            end loop

            if File.Exists (location) then
                open : stream, location, get
                loop
                    exit when eof (stream)
                    get : stream, char_name
                    get : stream, char_sex
                    get : stream, char_job
                    get : stream, char_level
                    get : stream, char_experience
                    get : stream, a_point
                    get : stream, h_point
                    get : stream, m_point
                    get : stream, s_point
                    get : stream, d_point
                    get : stream, i_point
                    get : stream, l_point
                end loop
                exit
            end if
        end if
    end if
end loop

