Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers DBPro Corner / saving and reloading

Author
Message
Raver
20
Years of Service
User Offline
Joined: 7th Dec 2003
Location: leeds
Posted: 5th Jul 2004 02:06
Hi, I want to save the contents of an array into a file..actually there are 3 arrays called xpos(),ypos() and bnum(), all are sized 99, so i want save the data in them to a file and then reload them back!!I did try this(see code) but it never worked!!

djwheeler
CattleRustler
Retired Moderator
21
Years of Service
User Offline
Joined: 8th Aug 2003
Location: case modding at overclock.net
Posted: 5th Jul 2004 02:15
did the files get written?

do the write and then stop and check the files


* DBP_NETLIB_v1.4.3 - July, 2004 * Click Logo
Raver
20
Years of Service
User Offline
Joined: 7th Dec 2003
Location: leeds
Posted: 5th Jul 2004 02:17 Edited at: 5th Jul 2004 02:19
actually here is all the code,so you can see w00ts going on,i have changed the load routine to what it was b4 i fiddled with it..still doesnt work mind,i get an error saying object doesnt exist at line 34 when i try to load..and by my counting,line 34 is the loop command!!save works fine, but perhaps it isnt saving properly??dunno

djwheeler
Raver
20
Years of Service
User Offline
Joined: 7th Dec 2003
Location: leeds
Posted: 5th Jul 2004 02:17
yes..the file gets created!

djwheeler
Raver
20
Years of Service
User Offline
Joined: 7th Dec 2003
Location: leeds
Posted: 5th Jul 2004 02:22
the irony is i check for objects existing anyhow to take care of such errors....if you paste the code into your preferred editor you will see why aswell!!you just need a bmp or take the texturing out..doesnt matter

djwheeler
SandraD
20
Years of Service
User Offline
Joined: 30th May 2004
Location: Down on the corner, out in the street.
Posted: 5th Jul 2004 02:46
Well, the first I'd look at is the actual WRITE commands you are using, for each one is specified as BYTE. If the values in the array are larger than 255, you want to use the WRITE WORD or WRITE LONG command instead to handle the value.

Second, you could try changing the READ command a little to not use the array itself as the target, as in READ WORD I, xpos(n) = I instead of pointing directly. The reason I suggest this is because I had to make a similar change to a scrolly help display in order for the READ command to work, so I think it "gets lost somehow" when reading the arrays directly.

Let us know if this helps,
S.

Any truly great code should be indisguishable from magic.
Raver
20
Years of Service
User Offline
Joined: 7th Dec 2003
Location: leeds
Posted: 5th Jul 2004 02:58
ok,did the changes as seen in the code, but same error, object doesnt exist at line 34,its a dumb error message actually,as line 34 is the loop command as i said, but hey, thats basic 4 u!!

djwheeler
SandraD
20
Years of Service
User Offline
Joined: 30th May 2004
Location: Down on the corner, out in the street.
Posted: 5th Jul 2004 03:05
Hehehehe.. oops....

Perhaps I should have been more clear in my posting. Here's what I meant about changing the read commands;


read word 1,i
xpos(n)=i
read word 1,i
ypos(n)=i
read word 1,i
objs(n)=i

The way you had it, all values would be set to the last value read from the file.

And yes, the LINE NUMBER of the error is almost NEVER correct. I think that has to do with the way that errors are checked, in that the command making the error has to finish before the error flag gets checked, so the line number is rarely one the correct line.

S.

Any truly great code should be indisguishable from magic.
Raver
20
Years of Service
User Offline
Joined: 7th Dec 2003
Location: leeds
Posted: 5th Jul 2004 03:12
well, a slight improvement, it creates a top row of cubes b4 it errors using your said code, but same error

djwheeler
Raver
20
Years of Service
User Offline
Joined: 7th Dec 2003
Location: leeds
Posted: 5th Jul 2004 03:34
ok..after abit of debuggin,well printing the contents of objs(n) to the screen after its read in..they all have a value of 0!lol..hmmm..so it isnt saving them correctly..must be my amazing code skills b4 its saved..must look into it..damn!!

djwheeler
SandraD
20
Years of Service
User Offline
Joined: 30th May 2004
Location: Down on the corner, out in the street.
Posted: 5th Jul 2004 03:40
Okay, I have looked at the code a little more off-line where I can poke around in it, and I've discovered a few things that concern me.

First, in the start of load you set about deleting all objects without regard to whether or not they exist, which may not work given what you want to do;

load:
for n=1 to 99
delete object n
next n

...So that code section of code should be;

load:
for n=1 to 99
if object exist(n)=1 then delete object n
next n

...providing that all objects use the numbers of 1 to 99.

Which brings me to my second concern... what is the value OPN supposed to be? The reason I ask is because in the control section you add to this value and subtract from it, sometimes adding or subtracting 11. In addition, you use this value to create and delete objects, but you never check it for being valid or in the range of 1 to 99. (Or 1 and up, like objects.)

Which brings me to my third point...

in the control section you change the values of XP, YP, XC and YC but only put the changes into the arrays of xpos() and ypos() when you CREATE new objects. So if the idea is to move things around and then save those positions the control section needs a re-write, to update the values saved in the arrays as you press the keys.


Now, the delete fix might make the error go away and it might not, but let's try it and see...
S.

Any truly great code should be indisguishable from magic.
Raver
20
Years of Service
User Offline
Joined: 7th Dec 2003
Location: leeds
Posted: 5th Jul 2004 03:45 Edited at: 5th Jul 2004 03:49
well..if you can visualise..you can have 11 cubes across and 9 down..hence 9*11 is 99..that would have objects 1-11 on the top row...if you press the down key..you have to add 11....think of it like a chess board i guess...that is why 11 is added and subtracted depending on moving up and down...it is entirely correct!!the object number created there after pressing space bar is then of course the value of obn!
and about the deleting bit..dunno..will look into it!
thanks for the help so far

the values of objs() were correct,not 0..i was printing from the console which doesnt really work so i printed them out within the code,so i am still clueless

djwheeler
SandraD
20
Years of Service
User Offline
Joined: 30th May 2004
Location: Down on the corner, out in the street.
Posted: 5th Jul 2004 03:50
Well, that works if all the cubes already exist and you are "hopping" from one to the other, but otherwise you might be creating/saving/loading objects that either already exist, or have numbers that you can use. (Like your player object.) I'll have to look into this one myself...

Any hey, no problem... I'm just avoiding confusing my brain on my latest project.
S.

Any truly great code should be indisguishable from magic.
Raver
20
Years of Service
User Offline
Joined: 7th Dec 2003
Location: leeds
Posted: 5th Jul 2004 04:00
well..no other objects exist..apart from the cursor cube..which i set to 200# so its well out of the way..if you run the code then you will see that there is no problem..you place a cube with space bar..and delete it with ctrl key..all works fine..the problem only occurs with saving/loading this store data

djwheeler
Raver
20
Years of Service
User Offline
Joined: 7th Dec 2003
Location: leeds
Posted: 5th Jul 2004 04:09
i took out the delete objects in the load: and as i expected it says object already exists..if you look on it at a practical point..then of course you delete them,then load data and recreate thm from the data...i am planning to save multiple levels,as soon as i get this problem fixed...so each level will be different...i am amking a arknoid type game..the cubes created are of course the bricks you hit..when i get this sorted i will resize the cubes actually to 64x32 if possible..or use a .x object..as arknoid fits more down than across..but i preplanned that anyhow..i just need this sorting out 1st

djwheeler
SandraD
20
Years of Service
User Offline
Joined: 30th May 2004
Location: Down on the corner, out in the street.
Posted: 5th Jul 2004 05:57
Well, the change I suggested to the delete function of laod should remove the existing objects without a problem, the trouble seems to be in that creating section when we load them back in for some god awful reason. And I understand about trying to use this to make multiple levels, I sort of figured that's what you had in mind anyway...

As for the other, sorting out the nature of the error here, guess I'm going to have to ding around with it a bit. I'll get back to you...

S.

Any truly great code should be indisguishable from magic.
Raver
20
Years of Service
User Offline
Joined: 7th Dec 2003
Location: leeds
Posted: 5th Jul 2004 07:14
hey,thanks!!i mean it should work..well..with the word type!!
the editor as you can see works..its just this damn loading/saving business

djwheeler
SandraD
20
Years of Service
User Offline
Joined: 30th May 2004
Location: Down on the corner, out in the street.
Posted: 5th Jul 2004 12:02
WELL...

BELIEVE ME IT WAS NOT EASY TO DETERMINE WHAT'S GOING ON!

But, I think I've solved it... by a means that really gave me some trouble.

[complaint mode on...]
What's happening here is that my screen is "FLASHING" bits and pieces of images saved in the video ram, meaning my Direct-X or hardware interface files have gotten messed up. I've tried re-installing but that hasn't worked yet, so I sort of had to live with the problem while I was working.
[complaint mode off...]



Anyway, here's the scoop -- the problem is in the READ WORD command. But it's not the command's fault -- it OUR fault, though I guess we could blame the command as if we wanted to. Here's what's happening;

When we write out a value to the level file it goes as RAW DATA, meaning it really is exactly two bytes. Trouble is, when we read the data the same is the case, but the read command doesn't like byte data so it tries to make the value into a number. In order to this, it makes the two bytes into a LONG number, meaning that a -1 for examples back with the value of 65535!

This means that although all the cubes are listed properly, their positions are all messed and way, way off screen. So, I propose trying this;

read word 1, i
if i > 32767 then i = i - 65536
xpos(n) = i

do that for each statement. And as for why you were getting a straight line of the blocks, those values were being saved correctly while the others were not. And you also forget a position command in the load;

if objs(n)
make object cube objs(n),64
position object objs(n), xpos(n), ypos(n), 0
endif

So try making these changes and see if that clears it all up.

ttfn, I'll keep playing with it too...
S.

Any truly great code should be indisguishable from magic.
SandraD
20
Years of Service
User Offline
Joined: 30th May 2004
Location: Down on the corner, out in the street.
Posted: 5th Jul 2004 14:53
Well, I have determined that the correction does indeed function. Everything looks okay now. As for my hardware problem, I've managed to isolate it to something in the drivers, but not sure which file is causing the trouble. Ah well.. I'll figure it out.

Good luck with your efforts.
S.

Any truly great code should be indisguishable from magic.
Raver
20
Years of Service
User Offline
Joined: 7th Dec 2003
Location: leeds
Posted: 5th Jul 2004 19:04 Edited at: 5th Jul 2004 19:16
could you repost the corrected code??I have messed and fiddled with my code and seem to have lost my way!! ... Also, how did you find out the problem..loading up the created file looks like gobbly gook to me in notepad! And yes I blame DB for this..hehe..Well the fact is I have done editors in other languages..like blitz basic and pure basic, ok it was 2d editors..but hey its all the same!!And they worked fine!Anyhow if you could post the corrected code I would be grateful... Also one last thing, the codebase has examples that wont work with my db classic, even though they indicate that their for db classic, and no it is no asking for missing media! Just odd errors!Now is db backwards compatible or does older code not work with updated db?

djwheeler
SandraD
20
Years of Service
User Offline
Joined: 30th May 2004
Location: Down on the corner, out in the street.
Posted: 6th Jul 2004 00:37 Edited at: 6th Jul 2004 00:40
Sure... I can send up the corrected code... along with the "how did you figure this out?" portion I added. Basically, I added a short routine to the control section to print out the values over a 2D box image, then watched the data closely. Feel free to remove that section as you decide.

S.

PS: I did solve my hardware driver problem BTW, it was the Direct-X interface files from my card. Seems the new drivers have a bug in them, so I had to go back to an older version for those 2 files.

TTFN!

PSS: Oh yes! I had to rem out your texture commands, because I didn't have the media files you asked for. They will need to be put back in.

Any truly great code should be indisguishable from magic.
Raver
20
Years of Service
User Offline
Joined: 7th Dec 2003
Location: leeds
Posted: 6th Jul 2004 02:03
its very close!!but..i mean i thought you had sussed it..but after i save/load the level,there are some places where i can no longer put a cube into!!wierd eh??maianly around the middle bit..try filling the whole screen with cube and you will see!!after reloading that is!

djwheeler
Raver
20
Years of Service
User Offline
Joined: 7th Dec 2003
Location: leeds
Posted: 6th Jul 2004 02:06
oh..never mind!I just had to reset the vars:
obn=1
xp=0
yp=0
yc=1
on=2
into the load routine..yep..works fine..thanks alot!

djwheeler
SandraD
20
Years of Service
User Offline
Joined: 30th May 2004
Location: Down on the corner, out in the street.
Posted: 6th Jul 2004 03:03
Hey, no problem... glad I was finally able to sort this one out.

Any truly great code should be indisguishable from magic.
SandraD
20
Years of Service
User Offline
Joined: 30th May 2004
Location: Down on the corner, out in the street.
Posted: 6th Jul 2004 10:14
Yeah, the reason you had to reset them there is because you reset obn to 1 in that section but didn't do the rest. If you take it all out, it should work as well.

Any truly great code should be indisguishable from magic.

Login to post a reply

Server time is: 2024-09-22 16:35:21
Your offset time is: 2024-09-22 16:35:21