Qbasicnews.com

Full Version: Bsave and Bload problems...
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2 3
I’m having problems with loading sprites with BSAVE and BLOAD, I’m trying to save a sprite to a file with one program, and the open it with another program. Here’s my code:

Code:
‘saving sprites

DEF SEG = &HA000
BSAVE "yay.dat", 0, 199
DEF SEG
DATA 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10
DATA 10,10,10,10,10,10,10,10,10,10,10,02,10,10,10
DATA 10,10,10,10,10,10,10,10,10,10,02,10,10,10,10
DATA 10,10,10,02,10,10,10,02,10,10,02,10,10,10,10
DATA 10,10,10,10,02,10,02,10,10,10,10,10,10,10,10
DATA 02,10,10,10,02,10,02,10,10,10,02,10,10,10,10
DATA 10,02,10,10,02,10,02,10,10,02,10,10,02,10,10
DATA 10,10,02,02,10,02,10,10,10,02,10,02,10,10,10
DATA 10,10,10,10,10,10,10,10,10,02,10,02,10,10,10
DATA 02,02,10,10,02,10,10,10,02,02,02,10,10,10,10
DATA 10,10,02,02,10,10,10,10,10,10,10,10,10,10,10
DATA 10,10,10,10,10,10,02,02,10,10,10,10,10,10,10
DATA 10,10,10,10,10,10,02,10,10,10,10,10,10,10,10



‘loading sprites

DIM sprite(50)
SCREEN 13
DEF SEG = &HA000
BLOAD "yay.dat", 0
PUT (1, 1), sprite

yeah, I figure I’m doing something wrong… I get an illegal function call when loading sprites, about five seconds into the program when I run the loading part.

Could someone lead me in the right direction? Thanks!
Here's an example of using BSAVE and BLOAD....

BSAVE:
Code:
DIM Sprite(52) 'A 10*10 Sprite
SCREEN 13
FOR nx = 0 TO 9
FOR ny = 0 TO 9
  PSET (nx, ny), INT(RND * 256)
NEXT ny
NEXT nx
GET (0, 0) - (9, 9), Sprite
DEF SEG = VARSEG(Sprite(0))
BSAVE "Test.dat", VARPTR(Sprite(0)), 416
'416 = Arrayelements * Bytes Per Pixel = 52 * 8
DEF SEG

BLOAD:
Code:
DIM Sprite(52)
SCREEN 13
DEF SEG = VARSEG(Sprite(0))
BLOAD "Test.dat", VARPTR(Sprite(0))
DEF SEG
PUT (0, 0), Sprite

BTW: Sometime the QB Help is a very helpful thing :wink:
Quote:Here's an example of using BSAVE and BLOAD....

BSAVE:
Code:
DIM Sprite(52) 'A 10*10 Sprite
SCREEN 13
FOR nx = 0 TO 9
FOR ny = 0 TO 9
  PSET (nx, ny), INT(RND * 256)
NEXT ny
NEXT nx
GET (0, 0) - (9, 9), Sprite
DEF SEG = VARSEG(Sprite(0))
BSAVE "Test.dat", VARPTR(Sprite(0)), 416
'416 = Arrayelements * Bytes Per Pixel = 52 * 8
DEF SEG

This one is not completely correct. The number of bytes saved = nº of array elements * Bytes per element; the sprite should be DIMMED to 10 * 10 \ 2 + 1 = 51 (i.e. 52 elements from 0 to 51), the BSAVED data = 52 * 2 = 104 bytes. The correct piece of code would've been:

Code:
DIM Sprite(51) 'A 10*10 Sprite
SCREEN 13
FOR nx = 0 TO 9
FOR ny = 0 TO 9
  PSET (nx, ny), INT(RND * 256)
NEXT ny
NEXT nx
GET (0, 0) - (9, 9), Sprite
DEF SEG = VARSEG(Sprite(0))
BSAVE "Test.dat", VARPTR(Sprite(0)), 104
'104 = Arrayelements * Bytes Per Array Element = 52 * 2
DEF SEG

Plus in SCREEN 13 you have 1 byte per pixel (if you had 8 bytes per pixel, you would have 2^64 possible colours Big Grin)
Oh damn...you're right...I didn't think, obviously :oops:
But Offensive Screename should have got the idea how to do it...
Of course, I was just correcting a *little* error you had Smile
That IS right...this code works (I tested it!!!)
It just saves tot much (better then less!!!)
:king:
Yeah..I did check the help file....I always do.. But it didn't have an example for saving/loading a bitmapped sprite from DATA....

anyways, thanks guys
When you use DATA, you have to save this stuff somewhere, let's say an array or something; then you can save that array (...) with BSAVE....ok?
Hmmm...okay

Easier Way? Have the DATA statements stored in a .dat file or whatever, then open them and get them with FOR...NEXT loops and GET and PUT? Kinda like the same way people would use it for map files, but just with sprites this time. Is it possible?
Yes. But it's better to BSAVE your sprites in GET/PUT format, as Akooma has explained. Then you can just BLOAD them in a blast.

THis comes handy 'cause you have limited memory and it's better to load only the used tiles/sprites at the beginning of each level ('cause they change Wink)
Pages: 1 2 3