Author Topic: Program hangs up because of DOESFILEEXIST()  (Read 3322 times)

Offline S. P. Gardebiter

  • Mr. Polyvector
  • ***
  • Posts: 245
    • View Profile
    • Tile 44 Interactive
If I execute the following code, my program hangs up for whatever reason:

Code: (glbasic) [Select]
LET Config
LET ConfigSaved
LET file$

Config = DOESFILEEXIST("Config.dat")
IF Config
ConfigSaved = TRUE
OPENFILE(1, "Config.dat", TRUE)
READLINE 1, file$
CLOSEFILE 1
GOTO Open
ELSE
ConfigSaved = FALSE
PRINT "Please type exectuable name:", 16, 16
INPUT file$, 16, 32
GOTO Open
ENDIF
~ Cave Story rules! ~

Offline PeeJay

  • Mr. Polyvector
  • ***
  • Posts: 244
    • View Profile
    • PeeJays Remakes
Program hangs up because of DOESFILEEXIST()
« Reply #1 on: 2008-Mar-26 »
Aaaargh, the curse of GOTO - and what is LET????

Try this:-

Code: (glbasic) [Select]
LOCAL Config,ConfigSaved,file$

Config = DOESFILEEXIST("Config.dat")
IF Config=TRUE
    ConfigSaved = TRUE
    OPENFILE(1, "Config.dat", TRUE)
    READLINE 1, file$
    CLOSEFILE 1
ELSE
    ConfigSaved = FALSE
    PRINT "Please type exectuable name:", 16, 16
    INPUT file$, 16, 32
ENDIF
OpenFunc(ConfigSaved,file$)

FUNCTION OpenFunc: ConfigSaved,file$
.
.
.
ENDFUNCTION
www.peejays-remakes.co.uk
For games, remakes, and GL Basic Tutorials
Artificial Intelligence is no match for Natural Stupidity

Offline S. P. Gardebiter

  • Mr. Polyvector
  • ***
  • Posts: 245
    • View Profile
    • Tile 44 Interactive
Program hangs up because of DOESFILEEXIST()
« Reply #2 on: 2008-Mar-26 »
Ahh yea, much better. Thanks.
So it doesn't work with GOTO?
~ Cave Story rules! ~

Offline PeeJay

  • Mr. Polyvector
  • ***
  • Posts: 244
    • View Profile
    • PeeJays Remakes
Program hangs up because of DOESFILEEXIST()
« Reply #3 on: 2008-Mar-26 »
GOTO works, but it is horrible! The problem with GOTO is that it breaks up program logic, and can be too easy to get into an endless loop. With this in mind, it is considered very bad practice to use GOTO in code these days.

Happy to help :)

Edit: As you can see by my code edit, it is easy to pass local variables to a function, and is preferable to having loads of GLOBAL variables - again, it makes for neater, self contained code - once you have written your "OpenFunc:" function, you could just copy and paste it into your next project with no need to edit anything ;)
www.peejays-remakes.co.uk
For games, remakes, and GL Basic Tutorials
Artificial Intelligence is no match for Natural Stupidity

Offline bigsofty

  • Community Developer
  • Prof. Inline
  • ******
  • Posts: 2696
    • View Profile
Program hangs up because of DOESFILEEXIST()
« Reply #4 on: 2008-Mar-26 »
Spots a "GOTO"... runs away!,,, :giveup:
Cheers,

Ian.

“It is practically impossible to teach good programming style to students that have had prior exposure to BASIC.  As potential programmers, they are mentally mutilated beyond hope of regeneration.”
(E. W. Dijkstra)

Offline Ian Price

  • Administrator
  • Prof. Inline
  • *******
  • Posts: 4159
  • On the shoulders of giants.
    • View Profile
    • My Apps
Program hangs up because of DOESFILEEXIST()
« Reply #5 on: 2008-Mar-26 »
I haven't used a GOTO since coding on the CPC, 20 years ago! It has its uses, but to me it's pure evil in code form. :p
I came. I saw. I played.

Offline Kitty Hello

  • code monkey
  • Administrator
  • Prof. Inline
  • *******
  • Posts: 10758
  • here on my island the sea says 'hello'
    • View Profile
    • http://www.glbasic.com
Program hangs up because of DOESFILEEXIST()
« Reply #6 on: 2008-Mar-27 »
If I have a double nested loop (for x... for y... ) and want to exit from inside,  use goto. Only there.

Offline Moru

  • Administrator
  • Prof. Inline
  • *******
  • Posts: 1792
    • View Profile
    • Homepage
Program hangs up because of DOESFILEEXIST()
« Reply #7 on: 2008-Mar-27 »
*shudder* that would certainly cause troubles with some basic dialects. If you jump out of the nested for...next It would spend the rest of the program searching for the missing nexts :-)

Only time I ever used GOTO was in the same sentence as ON ERROR :-)

Oh, and in assembler when doing just about anything... BEQ or whatever :-)