Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
D&D Character Program
#11
statements, e.g.,

PUT #1, 1, savecharacter
PUT #1, 2, savestats
PUT #1, 3, saveweapon1
PUT #1, 4, saveweapon2

The numbers after the first comma refer to byte positions. If your variables are more than one-byte long (and they are), you're overwriting data. Since you're writing the file sequentially, you can just do


PUT #1,, savecharacter
PUT #1,, savestats
PUT #1,, saveweapon1
PUT #1,, saveweapon2


Otherwise, you have to take into account the byte-size of your variables when you specify the position.
ravelling Curmudgeon
(geocities sites require copying and pasting URLs.)
I liked spam better when it was something that came in a can.
Windows should be defenestrated.
Reply
#12
would it make a difference using the input, output or append words instead of the random or binary.
I am the Great Destroyer"
-Duo Maxwell 'Gundam Wing'
Reply
#13
If you want a text file, OUTPUT or APPEND would work. But BINARY should work too. You just have to access the file right. Presuming you're passing everything to the subroutine correctly, i.e., it has the data it needs to write, try the PUT# without the position specifiers and see what happens.
ravelling Curmudgeon
(geocities sites require copying and pasting URLs.)
I liked spam better when it was something that came in a can.
Windows should be defenestrated.
Reply
#14
... is to use a RANDOM type file and store your information in records (see the TYPE statement). Then you can open the RANDOM file and specify the record length, for example:

Code:
' create the record TYPE.  let's call it "DataType"

TYPE DataType
  TheirName AS STRING * 10
  TheirAge AS INTEGER
END TYPE

'create array of records, each one looks like the TYPE

DIM Person(1 TO 10) AS DataType

'fill the array with some values, just to see how they work

FOR i = 1 TO 10
  PRINT "Entering data for person "; i
  INPUT "Enter Name: ", TempName$
  INPUT "Enter Age: ", TempAge

  Person(i).Name = TempName$
  Person(i).Age = TempAge
NEXT i

'now that the array is full, save the 10 records to the
'first 10 "spots" in a RANDOM file

OPEN "people.dat" FOR RANDOM AS #1 LEN = LEN(Person)
  FOR i = 1 TO 10
    PUT #1, i, Person(i)
  NEXT i
CLOSE #1

'now let's get the information out of the file and print it to the
'screen.  first we need a place to store the information that's
'the same TYPE as our record.  note that we don't need an array
'for this.  One variable of the TYPE will do:

DIM OnePerson AS DataType

'now we can get the info that we saved to the file.

OPEN "people.dat" FOR RANDOM AS #1 LEN = LEN(Person)
  FOR i = 1 TO 10
    GET #1, i, OnePerson
    PRINT "Information stored in file, location #"; i
    PRINT "Name: "; OnePerson.Name
    PRINT "Age: "; OnePerson.Age
  NEXT i
CLOSE #1

Hope this makes sense!

*peace*

Meg.
Reply
#15
incidentally, i can see where you're getting the type mismatch error in the code you posted up top. you're doing the same thing i see a lot of coders do when working with TYPEs.

When you make a data TYPE, you are making a new "kind" of variable, just like an integer, or a string. It's a type. You do this with the TYPE statement.

Once you make a type, you have to declare a VARIABLE to be OF that type. You do this with the DIM statement.

You can then manipulate the variable.

Here's an example:

Code:
TYPE DataType
  FirstName AS STRING * 10
  MiddleInit AS STRING * 1
  LastName AS STRING * 10
END TYPE

DIM FullName AS DataType

See? Now you have a VARIABLE ("FullName") of TYPE "DataType"

You can manipulate the variable:

Code:
FullName.FirstName = "Marvin"
FullName.MiddleInit = "B"
FullName.LastName = "Edison"
INPUT "Enter First Name: ", FullName.FirstName
IF FullName.MiddleInit = "B" THEN PRINT "Your middle init is B!"

All of these are valid commands.

***THIS IS NOT***

Code:
DataType.FirstName = "Marvin"

***THIS IS NOT***

You can't manipulate the data type like that. It's like trying to say

Code:
INTEGER = 4

*peace*

Meg.
Reply
#16
are more things that you need to be aware of when you use any type of binary file instead of a text file (and a RANDOM file is still a "type" of binary file). Maybe you should just post your entire program.
ravelling Curmudgeon
(geocities sites require copying and pasting URLs.)
I liked spam better when it was something that came in a can.
Windows should be defenestrated.
Reply
#17
right now I'm trying to get the data to be displayed. I probably will have to post my entire code. Actually I think I need to probably weed out some of my type statements. I think I have to many. Any ways...the only wrong is that my opening says that the record length isn't correct or something, then when I change a variable. It sometimes works. I dunno at this point.
I am the Great Destroyer"
-Duo Maxwell 'Gundam Wing'
Reply
#18
I am using the type statements correctly. That part is right. I think my problem is still in the darn manipulation of moving the data to and from the subs.
I am the Great Destroyer"
-Duo Maxwell 'Gundam Wing'
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)