scripting engine

If you have questions about any aspect of QBasic programming, or would like to help fellow programmers solve their problems, check out this board!

Moderators: Pete, Mods

Post Reply
Jony_Basic
Newbie
Posts: 4
Joined: Tue Jun 27, 2006 3:24 am
Location: New York
Contact:

scripting engine

Post by Jony_Basic » Sat Dec 02, 2006 3:48 am

I have implimented a scripting engine that works as follows, and I need
some advice as to how to call up the script.

script file:

Code: Select all

<h>                         'header
30,30,s1                   'coordinates of script #1 on the map
</h>                        'end of header
<s1>                        'beginning of script #1
some commands       'self explanitory
</s>                        'end of script #1
</>                          'end of file
the program will call this script file and check the header for matching
coordinates. If a match is found, the program will jump to the s# defined
in the respective header.

This is my dilemma:

If I decide to hold this file open for input for the length of the programs
run, I fear the program is liable to crash without warning due to
file access errors or some other problem related to holding a file open.
Perhaps my fears are completely illogical and there's no problem with
this method.

If I decide to only open the file when I need to read a script. I will load
the coords into the program then close the script file. the problem with this method is that constant opening and closing of a file may cause a
problem with the users hard drive. Of course I don't know, maybe it won't,
that's why I'm asking. also the fact that you are accessing the HDD at all
slows down the program by a bit. would it still be fast enough?

Please help me decide on a proper method of file access.
I hope to resolve this dillema by tomorow
any help is greatly appreciated, thank you. =D

User avatar
sid6.7
Veteran
Posts: 318
Joined: Tue Jun 21, 2005 8:51 am
Location: west USA
Contact:

Post by sid6.7 » Sat Dec 02, 2006 7:56 pm

if your appending the file you can keep it open
but if your doing something else you need to
open/close it as far as i know in QB.

Jony_Basic
Newbie
Posts: 4
Joined: Tue Jun 27, 2006 3:24 am
Location: New York
Contact:

Post by Jony_Basic » Sat Dec 02, 2006 8:25 pm

The only thing I'm doing is opening the file for input. It only reads.
Can I hold the file open until the program terminates?
I know I CAN, but is it a good idea?

User avatar
Skyler
Coder
Posts: 16
Joined: Wed Jun 07, 2006 4:15 pm
Location: Delta Quadrant

Post by Skyler » Mon Dec 04, 2006 12:43 pm

Well, if Windows continually accesses your hard drive for its virtual memory, I don't see why it would be bad for you to continually open/close a file. The only "open file" problems you should run into are if you're trying to access the file at the same time your program is reading it.
For God so loved the world he gave His only begotten Son that whosoever believeth on Him shall have everlasting life.
John 3:16

RyanKelly
Coder
Posts: 48
Joined: Sun Jan 22, 2006 6:40 pm
Contact:

Post by RyanKelly » Tue Dec 05, 2006 8:56 pm

Most hard drives should be able to handle the continual access, and your operating system will most likely try to cache the information, but the real issue you'll face if a severe speed penalty. Depending on the amount of data you plan to store in your script, it might be a better idea to try and load all of it into memory, compiling it into a code if neccessary.

User avatar
Nodtveidt
Veteran
Posts: 826
Joined: Sun Jul 25, 2004 4:24 am
Location: Quebradillas, PR
Contact:

Post by Nodtveidt » Wed Dec 06, 2006 3:22 am

It really depends on the application. Reading scripts from the hard drive to run time-critical operations is never a good idea, but non-time-critical operations is fine and a good memory saver.

Jony_Basic
Newbie
Posts: 4
Joined: Tue Jun 27, 2006 3:24 am
Location: New York
Contact:

Post by Jony_Basic » Mon Dec 11, 2006 7:04 pm

okay.
I'm opening the file at the beginning of the application.
I'm closing it when you close the application.
I access data from the file by means of the SEEK command to address
any byte in the file.
The program doesn't crash so far, it's relatively easy to use, and it's
running wicked fast. :D my program is speed intensive, therefore frame
rate is a priority.
I'm currently running at about 73-78 FPS. :wink:

Post Reply