this is a simple output to a file
---------------------------------
open "gameoutc.jhn" for ourput as #1
outputstr$=name$+" "+str$(score)
print #1,outputstr$
close #1
input from the file
-------------------
open "gameoutc.jhn" for input as #1
if lof(1)>0 then
line input #1,inputstr$
end if
close #1
'above examples use sequential files.
'learn them first then move to random
'and/or binary.
You will need to save all variables in the game, and character positions. Make sure you save them in a nice easily read fashion, or the codeing can become a nightmare.
If you do it like he specifies there's no way of organizing your data. Lets say you have some game data---weapons for instance. Each weapon has the same kind of attributes, but the attributes are different, which makes each weapon unique. Here's a basic example:
First we make a record template:
Type weapondata
wName As String * 15
wType As Integer
wDamage As Integer
wSpeed As Integer
End Type
Each record contains a weapon name, type, damage and speed. Now lets take this record template and store it into a word, making it an object. Underneath the object are the record fields called Name, Type, Damage and Speed which are used as Weapon.keyword (i.e. Weapon.Name). First lets DIM our Weapon object:
Dim Weapon As weapondata
Now we should open the data file for the info to be stored in. In QBasicKing's example there was no order to the data being written. When you use a Type, it allows you to keep data consistent as records. i.e. record one would have a weapon name, type, damage and speed. The way we open the file is to take the record object (Weapon) and use its length as the record length for the file as follows:
Open "Weapons.dat" for Random Access Read Write as 1 Len=Len(Weapon)
Now lets say you have an existing Weapons.dat and want to find out how many weapons there are in the file. Take the length of the file and divide it by the length of Weapon, which tells us exactly how many weapons (records) are in the file:
MaxWeapons = LOF(1) / Len(Weapon)
Now that we have this information we can read all weapons into an array, or read them at will. We simply specify which record (a number between 1 and MaxWeapons) and GET it:
Get 1, recordnumber, Weapon
This reads data from the corresponding record into Weapon.Name, Weapon.Type, Weapon.Damage and Weapon.Speed
Likewise, if you want to write to a record simply specify the recordnumber to write data to. If you want to create a new record simply write to MaxWeapons + 1. Be sure to recalculate MaxWeapons after writing a new record.
What you end up with is a file containing records like a database. Each record is the same length. Weapon.Name is stored as 15 characters regardless if it is less than that. When you read in Weapon.Name you have to do RTRIM$(Weapon.Name) to remove spaces from the end, because it will be 15 characters.
The way QBasicKing described would write indescriminantly to the random access file, as if you were writing to a data file using sequential file writing (i.e. Open myfile for Input/Output). Random access files are powerful because they can be set up to hold huge amounts of data in an orderly fashion (records), and data can be retrieved super fast. If I were writing a game, I'd sure be using random access files instead of plain ole sequential data files. You can keep track of your data easier and there's no parsing at all.
There no problem at all. I've got a cousre about structures 6 month ago: it has to serve!
Hey! I've just went into an idea! My course was about structure handlind in C with dynamic memory access with pointers. Pointers, that qbasic can't handel so far can be access with this idea. I don't know if it works but I'm sure it can be.
In my courses, we got to make structures with data fields that correspond to the data structure adresse memory. I didn't try it so far but I'm sure that we can affect the data structure adresse to a structure itself.
But I've think of it, qbasic doesn't have support direct memory allocation, so forget it.
Oak. I realize you can write data to the HDD from QB, such as variables, but I need help with the COM port. Lets say you wanted to take INFO$ and send it through the COM port to your friends computer down the street via the internet. Exactly how much code would that take? I'm not looking for a huge program that supports like email and stuff, I just want the simple code to access the modem, dial up, and transferr the data. Is it really that complicated? What are your thoughts?
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.