Saving data in MSX-BASIC (Development Foros MSX)MSX Resource Center MSX Info Update - Finnish MSX madness at its best           
                       
English Nederlands Español Português Russian                  
 Noticias
   Página principal
  Almacén de noticias
  Temas de noticias

 Recursos
   Foros MSX
  Artículos
  Analisis
  Informe de ferias/RUs
  Álbum de fotos
  Ferias y encuentros
  Encuestas
  Enlaces
  Buscar

 Software
   Descargas
  Tienda Online

 MRC
   Quiénes somos
  Únete a nuestro equipo
  Donar
  Políticas
  Contacta con nosotros
  Enlázanos
  Estadísticas

 Buscar
 
  

  

 Login
 

Login

Contraseña




¿Aún no tienes una cuenta? ¡Conviértete en miembro del MSX Resource Center! ¡Únete a nosotros!.


 Estadísticas
 

Hay 100 invitados y 1 miembro en línea

Eres un usuario anónimo.
 

Foros MSX


Foros MSX

Development - Saving data in MSX-BASIC

Ir a la página ( 1 | 2 Siguiente página )
Autor

Saving data in MSX-BASIC

monotone27
msx user
Mensajes: 60
Publicado: Marzo 11 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
Sonic_aka_T

msx guru
Mensajes: 2268
Publicado: Marzo 11 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
pitpan
msx master
Mensajes: 1379
Publicado: Marzo 11 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


GuyveR800
msx guru
Mensajes: 3048
Publicado: Marzo 11 2004, 14:45   
Quote:

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.

Quote:

But, again, do not trust me very much


We've already learned not to do that.
BiFi
msx guru
Mensajes: 3142
Publicado: Marzo 11 2004, 14:50   
Quote:

>>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...
legacy
msx professional
Mensajes: 516
Publicado: Marzo 11 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?
GuyveR800
msx guru
Mensajes: 3048
Publicado: Marzo 11 2004, 20:31   
AFAIK it's a normal textfile
monotone27
msx user
Mensajes: 60
Publicado: Marzo 11 2004, 20:35   
Sonic,

Thanks for that piece of code! It worked perfectly!

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
Sonic_aka_T

msx guru
Mensajes: 2268
Publicado: Marzo 11 2004, 20:52   
Quote:

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...
legacy
msx professional
Mensajes: 516
Publicado: Marzo 11 2004, 21:24   
Quote:

AFAIK it's a normal textfile



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.
GuyveR800
msx guru
Mensajes: 3048
Publicado: Marzo 11 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.
legacy
msx professional
Mensajes: 516
Publicado: Marzo 11 2004, 21:48   
Quote:



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?




MSXbasic is almost similar to gwbasic, You can use many things of gwbasic, but I'm sure that there is an englisch edition of MSXbasic.
An other solution is, learning dutch. (lol)
Sonic_aka_T

msx guru
Mensajes: 2268
Publicado: Marzo 12 2004, 00:00   
Legacy:

I'm not really sure what it is you want to do, but if you somehow mean to parse the data you have in that text file, use the method I described earlier to open the file and retrieve the data line by line (using input#x,RD$) and then use the BASIC string manipulation commands to edit the data. Remember you can't use [ " ] and [ , ] in a text file written with PRINT #x,WR$

A string can be no longer than 255 chrs I think...
You can "add" strings by using C$=A$+B$

LEN(A$) will return the length of A$
LEFT$(A$,x) would return the x left-most characters of a string.
RIGHT$(A$,x) would return the x right-most characters of a string.
MID$(A$,x,y) would return the content of A$ from x onward, y characters.
MID$(A$,x,y)=B$ replaces the contenf of A$ at position x with y characters of B$.
STR$(x) would convert the value of x to a string.
VAL(A$) will give the numerical value of A$.
CHR$(x) gives a string containing character number x (ie CHR$(8) = TAB)
INSTR(x,A$,B$) checks A$ to see if it contains B$ from char x on.
(returns the position or 0 if A$ does not contain B$)

Hope that's what you need.... With these functions you can do surprising text manipulation, even in BASIC...

Good luck
monotone27
msx user
Mensajes: 60
Publicado: Marzo 12 2004, 08:05   
Quote:

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...



Thanks for the link. Unfortunatly, I still have one more question for you though (I promise this will be the last one ). The game I'm making has a 3-D dungeon type view and everytime I move it has to draw the whole screen over again which takes a VERY long time. I was wondering what commands I need to use to save the dungeon graphics into memory. I know in QBASIC I had to use GET and PUT, but I tried that and it didn't seem to work. Do I need to do something with POKE and PEEK?

Thanks,
Kevin
legacy
msx professional
Mensajes: 516
Publicado: Marzo 12 2004, 13:09   
You can do 2 things.
First you can create a ramdisk and put your data on it, from the ramdisk you can copy the data you need to the screen, this works really fast.
Second you can use the SET PAGE command.
You can use 2 or 4 pages. depend on witch screen you are using.
in screen 5 and 6 you can use 4 pages, in 7 and 8 you can use 2 pages.
How this command works?
SET PAGE 0,X. where page 0 is visible and page X is the active screen. X is 0 or 1 or 0 to 3.
You can load graphics to al the pages.
Then you can copy parts of a page to the visible screen.
I use this command in that plotterprogram that mention in this topic, to redraw the workscreen.

A combination of this 2 solutions is possible to

But it is about 7 years ago if I used this command, so if my explanation is not correct, everybody may correct or complete this explanation.
Re-edit
 
Ir a la página ( 1 | 2 Siguiente página )
 







(c) 1994 - 2008 Fundación MSX Resource Center. MSX es una marca registrada de MSX Licensing Corporation