Saving data in MSX-BASIC

Page 1/3
| 2 | 3

By monotone27

Resident (60)

monotone27's picture

11-03-2004, 01:45

I'm not too experienced with programing (QBASIC is pretty much all I know), but I'm trying to make a little RPG with MSX-BASIC. The problem is I want to be able to save the character's stats during the game and save it to a disk as a separate file, but I'm not sure how to do this. I tried the "save" command but that just resaves the entire program. Does anyone anyone know a command that I could use to do this?

Thanks,
Kevin

Login or register to post comments

By Sonic_aka_T

Enlighted (4130)

Sonic_aka_T's picture

11-03-2004, 02:12

Well, you can try opening a file and writing the data to it, if they're numbers, that is... Stats are usually numbers tho, and I think you can even save the occasional string like this.

OPEN "FILENAME.EXT" FOR OUTPUT AS #1
HP=100: MP=50: LV=10: N$="PLAYER1"
PRINT #1,HP
PRINT #1,MP
PRINT #1,LV
PRINT #1,N$
CLOSE #1

That should prolly do the trick. As long as there are no disk-errors (disk offline, write protect, disk full etc.) it should work. You could then even

OPEN "FILENAME.EXT" FOR INPUT AS #1
INPUT #1,HP
INPUT #1,MP
INPUT #1,LV
INPUT #1,N$
CLOSE #1

to retreive the data you saved. Try getting your hands on a good MSX-BASIC book though. If you really want to write an RPG in BASIC you'll probably need it. MSX-BASIC is powerful enough and people have made RPG's in BASIC before, but you'll need to know quite a bit about BASIC to do it. Try checking www.funet.fi/pub/msx to see if there is a BASIC handbook online there. It should help.

Good luck

By pitpan

Prophet (3132)

pitpan's picture

11-03-2004, 07:29

Another way to do this, faster but less clear is the following:

-Copy all the vars to a continuous block of RAM starting in a given address.
-Execute then BSAVE"DATA.BIN",START,START+LENGHT

Of course, START is the address where the data starts, and LENGHT is the total lenght in bytes.

To retrieve the data:
-Execute BLOAD"DATA.BIN"
-Then you have got all the data in the same position of RAM.

Of course, to move all the data you should use POKEs. But you can define the var space using CLEAR. But, again, do not trust me very much, because my BASIC times faded away.

Regards,

Ed Robsy

By anonymous

incognito ergo sum (118)

anonymous's picture

11-03-2004, 14:45

Another way to do this, faster but less clear is the following:

-Copy all the vars to a continuous block of RAM starting in a given address.
-Execute then BSAVE"DATA.BIN",START,START+LENGHT
That's not faster at all! Do you think the copying of all the variables using POKE is free? And how the hell do you get them back?! It would take many, many extra lines of programming, and be prone to mistakes.

But, again, do not trust me very much
We've already learned not to do that.

By BiFi

Enlighted (4348)

BiFi's picture

11-03-2004, 14:50

>>But, again, do not trust me very much<<
We've already learned not to do that.
I wonder how many doors have remained in 'working' condition at pitpan's home... Smile

By legacy

Hero (570)

legacy's picture

11-03-2004, 19:34

I know how the in and output commands works, but I'v an other question, I wrote a util that works with the sony plotter, and i'v implement some rudiment drawingfunctions.
The drawing can be saved as a HPGL plotfile, using open "filename.plt" for output as#1: print #1, x,y. For example I made a error and I'll change that drawing.
My question is, how can I manipulate the data somewhere in the middle of the saved file?

By anonymous

incognito ergo sum (118)

anonymous's picture

11-03-2004, 20:31

AFAIK it's a normal textfile Smile

By monotone27

Resident (60)

monotone27's picture

11-03-2004, 20:35

Sonic,

Thanks for that piece of code! It worked perfectly! Smile

I looked through Funet for some MSX-BASIC info, but I couldn't find any. Maybe I wasn't looking hard enough though. I found some books on Ebay, but none of them were in English (which is the only language I speak). Does anyone out there have any links to English MSX-BASIC info?

Thanks,
Kevin

By Sonic_aka_T

Enlighted (4130)

Sonic_aka_T's picture

11-03-2004, 20:52

Does anyone out there have any links to English MSX-BASIC info?

Fraid not... www.geocities.com/SiliconValley/Bay/9797/th-2.txt has *some* info, not too much tho. I have a Dutch manual, but I doubt that's gonna help you much. If you want some info on a command tho, feel free to post... I'll try to translate whatever my handbook says. Ofcourse my handbook was written by someone who didn't know dick about MSX BASIC, but hey... Can't have it all...

By legacy

Hero (570)

legacy's picture

11-03-2004, 21:24

AFAIK it's a normal textfile Smile

Indeed it is, it can be read with any wordprosessor.
But what I mean is, if I (re)load that drawing, than I like to select a line or something else
that I'll change. I'm looking for a solution of that problem.
It would be nice if I select a line, and I can use some grips to change that line.

By anonymous

incognito ergo sum (118)

anonymous's picture

11-03-2004, 21:46

well, you'll need to write some software to do that, I think.. I'm not familiar with plotter software, so I have no idea if it already exists or not.

Page 1/3
| 2 | 3