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 / problems loading an array.

Author
Message
sheffieldlad
12
Years of Service
User Offline
Joined: 28th May 2011
Location:
Posted: 16th Apr 2012 22:36
hi all.
this follows on from a post i made in DBpro discussion.
I feel I posted the origional thread in the wrong board (sorry) so I've started over here...

I'm having problems loading an array I have saved.

here is the code



the array count returns -1 (empty) when it should contain the data the user typed in at the strart of the program.

Can anyone see a reason for this?

Many thanks,

Paul.

pogo: http://dl.dropbox.com/u/65597655/pongo.zip
Breakout clone: http://forum.thegamecreators.com/?m=forum_view&t=185535&b=6
sheffieldlad
12
Years of Service
User Offline
Joined: 28th May 2011
Location:
Posted: 16th Apr 2012 22:57
I fixed it.
I had to redim the array before I reloaded it.

pogo: http://dl.dropbox.com/u/65597655/pongo.zip
Breakout clone: http://forum.thegamecreators.com/?m=forum_view&t=185535&b=6
DVader
20
Years of Service
User Offline
Joined: 28th Jan 2004
Location:
Posted: 16th Apr 2012 23:22 Edited at: 16th Apr 2012 23:24
Hi, I feel your pain, strings can be awkward. Here's some code from an old GAC remake I was trying to do. It is from DB Pro, but it may help you with this.

I don't think DB is too different from Pro, it has been many years since I have used it. So you should be able to use this with little or no modification. Obviously, you may need to tinker a little to get it to work for you, but that code is fairly decent for splitting strings into words. Saving the array should be fairly simple from there.
Looking at your save code, you seem to try to get data into variable t with this.

t = array count(myarray$())

I assume it is a command in DB. I have never really used them, as they were badly bugged at the time. I have no idea if that was fixed or not. I would save the size of the array in the first (0) element of the array, and check that instead personally. Then you can simply use.

t= myarray$(0)

That way regardless of size you always know the first element holds the total size of the array. Hope that helps.

Edit - lol, fixed before I finished my post. Still the code may help you tidy yours up a little anyway

sheffieldlad
12
Years of Service
User Offline
Joined: 28th May 2011
Location:
Posted: 16th Apr 2012 23:36 Edited at: 16th Apr 2012 23:38
Many thanks for your reply.
I'm using DBpro.

The reason I used t = array count(myarray$()) is because I wanted to know how many elements are in the array.
It's going to change every time someone types a command so I figured the best way to do this was to count the entries and place them in a variable that I can count to when i retrieve them.

The first element of my array will contain data entered by the user and I have no idea how to shunt the contents of the array on 1 and write the size of the array to 0.
I suppose I'd have to write it after the count and before I add the elements.
I'll give that a try, many thanks
That actually sounds like a great way of doing it

My way does work but yours sounds much much neater.
I'll give that a go tommorow.

Thanks again,

Paul.

edited for typo. probably didn't get them all :/

pogo: http://dl.dropbox.com/u/65597655/pongo.zip
Breakout clone: http://forum.thegamecreators.com/?m=forum_view&t=185535&b=6
DVader
20
Years of Service
User Offline
Joined: 28th Jan 2004
Location:
Posted: 18th Apr 2012 22:50
Ah, I saw your post on the Dark Basic forum first so thought it was in DB I didn't notice this was DB Pro newcomers, I just looked for your new post.
Regarding using element 0, you simply start the users info at element 1 when you insert data. Just because an array starts at 0, doesn't mean you have to add data in from there. Just start your word count from 1, and save it in element 1, rinse and repeat. At the end, when you have all the data in you simply save your word count to element 0. If you want to edit it, you can get your word count from element 0, to get your position in the array.

When working with arrays I am not overly worried about keeping them trimmed to size. I make them larger than I need and just use the array count to limit how far into it I read and increase as needed. But you could of course make a new array, and feed the contents of the old one into the new one at the correct size easily enough.

Login to post a reply

Server time is: 2024-05-17 06:38:37
Your offset time is: 2024-05-17 06:38:37