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 / array lists

Author
Message
someone namedlink
20
Years of Service
User Offline
Joined: 3rd Aug 2004
Location: Dream Planet
Posted: 17th Aug 2004 05:22
can someone give me some more info about lists please? i\'m using dbp and i tried to make a list and save it but it didn\'t work???

DIV/DBP-coder
IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 17th Aug 2004 05:50
Um, what exactly did you try?

Maybe you should show some example code - or check my examples in the CodeBase.

*** Coming soon - Network Plug-in - Check my site for info ***
For free Plug-ins, source and the Interface library for Visual C++ 6, .NET and now for Dev-C++ http://www.matrix1.demon.co.uk
Dodo
20
Years of Service
User Offline
Joined: 8th Aug 2004
Location: eating lunch
Posted: 17th Aug 2004 05:59
ill tell you what ill write a little tutorial. try running this and see if it works.

first you have to make an array



The Array can be any type of variable defined by the symbol at the end of the name ($=holds Strings,#=holds real numbers,nothing=holds integers)

the number(s) in the brackets at the end tell DB how big to make the array. e.g. think of an array as lots of storage boxes. within each box are more boxes and in each of these boxes, more boxes etc. the first number is the number of original boxes, the second number the number of boxes within each original box and so on.

next, you need to tell DB what to store in the array. you do this like you would with a normal variable e.g.


the numbers in the brackets tell DBP which "box" to store the data in.

so your code should now look something like this:



now to get it out, all you need to do is use it like a normal variable e.g.


if you were printing a whole array you should use for/next loop(s)

so now your code looks like this



to write it to a file, you should just use a write command:


your finalised code should look something like this



it is probably worth noting that an undefined(empty) "box" will be returned as an empty string or 0
someone namedlink
20
Years of Service
User Offline
Joined: 3rd Aug 2004
Location: Dream Planet
Posted: 17th Aug 2004 06:02
I looked at the codebase but in the file there is no discription on how you can save the list. and that's the problem. i can't save it and i need to do it.

DIV/DBP-coder
Dodo
20
Years of Service
User Offline
Joined: 8th Aug 2004
Location: eating lunch
Posted: 17th Aug 2004 06:12
actually my tut explains that
someone namedlink
20
Years of Service
User Offline
Joined: 3rd Aug 2004
Location: Dream Planet
Posted: 17th Aug 2004 06:25
but then it is very difficult to load it again
i though of something like save array. but save array doesn't work

DIV/DBP-coder
Dodo
20
Years of Service
User Offline
Joined: 8th Aug 2004
Location: eating lunch
Posted: 17th Aug 2004 06:36
ok, so i scanned the help for an easier way to save an array and came up with... save and load array. use like this:



Note: DB ignores the index numbers but you must provide them or the command will fail

if this still doesn't work all i can say in answer to your question is "I dunno "
someone namedlink
20
Years of Service
User Offline
Joined: 3rd Aug 2004
Location: Dream Planet
Posted: 17th Aug 2004 07:18
that doesn't work

DIV/DBP-coder
someone namedlink
20
Years of Service
User Offline
Joined: 3rd Aug 2004
Location: Dream Planet
Posted: 17th Aug 2004 19:10
I think I found the problem, When u use an array as a list, you can save it, but when you say: dim cards() as card, card being a user defined type, the array can't be saved anymore???? how can you solve this???

DIV/DBP-coder
Dodo
20
Years of Service
User Offline
Joined: 8th Aug 2004
Location: eating lunch
Posted: 17th Aug 2004 19:51
errm im afraid you might have to take the long way of doing it and use a seperate array for every thing in your card type. i tried it too and it doesn't want to work with user defined types. oh well...
Colin Hart
21
Years of Service
User Offline
Joined: 28th Apr 2003
Location: United Kingdom
Posted: 17th Aug 2004 21:27
post your custom type on the board...

i will write an example round that for you..
Colin Hart
21
Years of Service
User Offline
Joined: 28th Apr 2003
Location: United Kingdom
Posted: 17th Aug 2004 23:38
Ok the only way to write your typed aray to file is one varible at a time. so best to write a little routine to write all the varible for the nth value inthe record.

I have written abasic example... hope it helps.. jsut shout if you get stuck..
someone namedlink
20
Years of Service
User Offline
Joined: 3rd Aug 2004
Location: Dream Planet
Posted: 17th Aug 2004 23:41
ok I tried to save it on another way, but it is not working:



dbp gives no errors, so it's supposed to work, but when I display all items on the screen: there's nothing!

DIV/DBP-coder
the_winch
21
Years of Service
User Offline
Joined: 1st Feb 2003
Location: Oxford, UK
Posted: 18th Aug 2004 00:01 Edited at: 18th Aug 2004 00:08
I would be much simpler just to use the READ/WRITE STRING commands.

Something like this (not tested)



I'm not sure the complication of using a dynamic array is worth it either. There are a constant number of cards in most card games. Is the dynamic array really required?

shrink those dbpro exes
Create patches for your dbpro games
someone namedlink
20
Years of Service
User Offline
Joined: 3rd Aug 2004
Location: Dream Planet
Posted: 18th Aug 2004 00:08
Not in the game I'm making. At the moment I'm making the card maker, so I can put in the card and then it is saved with the other. So the cards can be used in the game itself. Each time there are new cards, I must give them in, so the number of cards is always unknow.

DIV/DBP-coder
someone namedlink
20
Years of Service
User Offline
Joined: 3rd Aug 2004
Location: Dream Planet
Posted: 18th Aug 2004 01:04
make file "cards.txt"
open to write 1,"cards.txt"
write string 1,"Hallo"
close file 1

this does not work! I get an empty file!

DIV/DBP-coder
Physics coder
20
Years of Service
User Offline
Joined: 25th May 2004
Location: United States
Posted: 18th Aug 2004 02:04 Edited at: 18th Aug 2004 02:06
you shouldn't need the make file command, in fact the file "cards.txt" CANNOT exist when you call the command "open to write."

From the dbp help files:

Quote: "OPEN TO WRITE
This command will open a file, ready for writing. The file must not exist or the command will fail. You can
open up to 32 files at the same time, using a file number range of 1 through to 32.

SYNTAX
OPEN TO WRITE File Number, Filename

"


also, I'm pretty sure you need to save the code as a dbp file before you can save/load any image/object/files whatever.

EDIT:
I'm not sure if this line would work:
write string 1,"Hallo"

if the code doesn't work try this when writing things:
s$="Hallo"
write string 1,s$

-----------------------------------
To delete the bug, delete the code.
Specs: Sony VAIO Laptop, Windows XP, P4 2.8Ghz, 512MB RAM, ATI Radeon 64MB video memory, DBP Upgrade 5.3.
Oneka
20
Years of Service
User Offline
Joined: 24th Apr 2004
Location: Hampton,VA
Posted: 18th Aug 2004 02:06
I know I thought I was supposed to make a file first....so then wtf is the command for then?


Making better games everday!
Oh yeah and just so you know its Oh-nek-a not One-ka!
Physics coder
20
Years of Service
User Offline
Joined: 25th May 2004
Location: United States
Posted: 18th Aug 2004 02:37
i dunno, didn't even realize that command existed before you mentioned it.

Here I took a couple minutes and made a simple save/load game. It saves the player's position health and armor, though it could save and load whatever you want with a bit of editing. The main thing is to save and load the variables in the same order. example: if you save the x/y/z position and then the health, then you load the x/y/z position and then the health.
Before this code can work, save the code to something like saveloadgame.dba or whatever, close the dbp editor and load the dba file again. I've always had to do that for some reason or the code will run in a temp directory or something.



-----------------------------------
To delete the bug, delete the code.
Specs: Sony VAIO Laptop, Windows XP, P4 2.8Ghz, 512MB RAM, ATI Radeon 64MB video memory, DBP Upgrade 5.3.

Login to post a reply

Server time is: 2024-11-11 19:09:32
Your offset time is: 2024-11-11 19:09:32