Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
D&D Character Program
#1
This project I have been working on is for use with d&d roleplaying to help the players keep track of their characters as well as information about other peoples. I am currently having trouble with the passing of data to variables so that it can be saved. I am trying to save the types but my attempts have failed in a simple error message of ' Type Mismatch'. Any help would be greatly appreciated.

TYPE savcharfile
names AS STRING * 20
race AS STRING * 10
...
end type
...
DIM savecharacter AS savcharfile
...
savecharfile.name = charactername$
...
SUB charcreate (charactername$, characterplayer$)
...
CLS
PRINT "Saving"
PRINT
INPUT "Enter Name of File: ", file$
... ' This is were I've tried several different things to solve my problem.
OPEN file$ + ".dnd" FOR BINARY AS #1
PUT #1, 1, savecharacter
PUT #1, 2, savestats
PUT #1, 3, saveweapon1
PUT #1, 4, saveweapon2

END SUB
I am the Great Destroyer"
-Duo Maxwell 'Gundam Wing'
Reply
#2
haven't been passed to your subroutine or otherwise defined there. I don't know what the current variables are in your SUB statement, but you'd need to add the SAVECHARACTER variable:


SUB charcreate (charactername$, characterplayer$, SAVECHARACTER AS SAVCHARFILE))


Then, when you call CHARCREATE, it would be

CALL charcreate (charactername$, characterplayer$, SAVECHARACTER)
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
#3
You need to use RANDOM file access instead of BINARY. Binary is for accessing the individual bytes of a file, for example in the case of loading a picture or a string of numbers or something... whereas random is when you have a bunch of records that all have equal length.
Reply
#4
want at one time with BINARY files. (I do it quite regularly.)
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
#5
Well... I was going in and associating the variables in the sub routine like so...

savcharfile.names = charactername$

it would take it as valid till the test run...it would say type mismatch.

I want to save several TYPES. But i didn't know if the sub routine parentesis would be some long line of code or not. I've been trying to avoid that.
I am the Great Destroyer"
-Duo Maxwell 'Gundam Wing'
Reply
#6
isn't allowed inside your subroutine unless the subroutine knows about the SAVECHARFIL user-defined variable type. As with other statements, SUB statements can be quite long, certainly longer than 80 characters. But I try to avoid long lines too. If that's a big problem for you, you can make your variables global and not have to explicitly pass them to the subroutine by using a COMMON SHARED statement in your MAIN routine (after where you define the types):

COMMON SHARED /MYTYPES/SAVECHARACTER AS SAVECHARFIL [, ..., etc.]

or (if you aren't going to use multiple modules), you can do

DIM SHARED SAVECHARACTER AS SAVECHARFIL[, ..., etc.]

(Either statement replaces your current DIM statement.)

(The "/MYTYPES/" is just a label for the COMMON block. You can use about whatever name you like.)
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
#7
so that should be able to let me pass data back and forth through the variables with out the long coding? This could be a big help. I've been at this program for a month and this is the only thing I haven't been able to look through other codings to get an idea of how to do. LOL
I am the Great Destroyer"
-Duo Maxwell 'Gundam Wing'
Reply
#8
routines with the global variables. (And it might be safer to use the global variables. Usually, user-defined types pass just fine by explicitly referring to them in the SUB and CALL statements. However, I've found that QB sometimes screws it up, for no reason that I can find.)
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
#9
Code:
TYPE CharacterType
  CName AS STRING * 20
  Level AS INTEGER
  Experience AS LONG
END TYPE

DIM SHARED PC AS CharacterType, PBlank AS CharacterType

CALL CreateCharacter

END

===============================================

SUB CreateCharacter
  OPEN "players.dat" FOR RANDOM AS #1 LEN = LEN(PC)
    Spot = 0
    DO
      Spot = Spot + 1
      GET #1, Spot, PC
      IF LEFT$(PC.CName) = " " THEN
        DO
          INPUT "Enter Character Name: ", PC.CName
        LOOP UNTIL UCASE$(LEFT$(PC.CName)) >= "A" AND UCASE$(LEFT$(PC.CName)) <= "Z"
        PC.Level = 1
        PC.Experience = 0
        PUT #1, Spot, PC
        EXIT DO
      END IF
    LOOP
  CLOSE #1
END SUB
Reply
#10
the data isn't showing up in the file. I did the dim shared but the program seems to not be taking the input from the user & storing it. Its either that or my data isn't being opened properly. I don't know which right now. What would be a good way of opening the data.
I am the Great Destroyer"
-Duo Maxwell 'Gundam Wing'
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)