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.

DarkBASIC Professional Discussion / saving array in files

Author
Message
Plugged
22
Years of Service
User Offline
Joined: 30th Nov 2002
Location: Hertfordshire
Posted: 20th May 2005 02:10
hi basically i am trying to save a level and to do this i need to save several array now i want to keep all the data in one file although from what help says you can only save one array to one file because it asks for filename rather than file number. please post back if i am wrong or it there is another command i should use

cheers
Plugged


Work Hard; Play Harder ;
dugzilla
21
Years of Service
User Offline
Joined: 5th Aug 2003
Location:
Posted: 20th May 2005 02:45
Why do you need several arrays? You can store more than several items
in one array...Also you don't need to use arrays for saving game
level data. Right now I'm writing a general load/save/new game
file format
so every game I write I don't have to write this part. It's
going to store car,character,levels,pick-up items,health,etc. data
and if say for example my game is an adventure with no vehicles it'll
be smart enough to skip any variable not there. This is the time
consuming part,making all those variables,but once done I shouldn't
have to do it again......
David R
21
Years of Service
User Offline
Joined: 9th Sep 2003
Location: 3.14
Posted: 20th May 2005 03:00
Here's some code (example+working function). Its something I made a while ago, and some comments are wrong (since I built it with the intention of varying datatypes... but thats antoher story)

Here's the code:


(Save code before running)

If you need any help, I'll do so (since the crap comments)
Hope its useful

[url=www.lightningstudios.co.uk][/url]
RiiDii
20
Years of Service
User Offline
Joined: 20th Jan 2005
Location: Inatincan
Posted: 20th May 2005 03:12
It sounds like you are using the Save Array command. Save Array is very limited in how it can be used. It's only good for 1 dimensional, non-UDT arrays. Basically, to go beyond that functionality, you will have to write specific routines for saving different arrays.

"Droids don't rip your arms off when they lose." -H. Solo
REALITY II
David R
21
Years of Service
User Offline
Joined: 9th Sep 2003
Location: 3.14
Posted: 20th May 2005 03:16 Edited at: 20th May 2005 03:17
This may sound stupid RiiDii, but what the heck are UDT array's? Lots of people talk about them, but I've never had it actually explianed to me

I assume you *may* mean arrays with more than one 'unit' [dim anarray(1,1,1,1) as opposed to 'dim anarray(1)'] but Im not sure

Please explain!


[url=www.lightningstudios.co.uk][/url]
RiiDii
20
Years of Service
User Offline
Joined: 20th Jan 2005
Location: Inatincan
Posted: 20th May 2005 03:39
Sorry. UDT = User Defined Type
I personally find UDT's very usefull. The most recent TGC newsletter has an article about UDTs.
Basically, instead of a multi-dimensinal array (i.e. Dim h(15,3) ), you can use a UDT, like so.



They are actually just a little more difficult to use because they take away a minor amount of flexibility from a multi-dimensional array in that you have to reference the Type directly (i.e. StarShips(i).Armor) ) instead of indirectly using a variable (i.e. Starships(i,a) )

However, (imo) what they lose in flexibility is far more than made up in readability of the code. Anyone reading StarShips(n).Armor=100 pretty much knows exactly what is being done. No rem statement needed there.

"Droids don't rip your arms off when they lose." -H. Solo
REALITY II
Plugged
22
Years of Service
User Offline
Joined: 30th Nov 2002
Location: Hertfordshire
Posted: 20th May 2005 03:41
okay slight problem with the code lightening posted the arrays are using types and could any number of lengths but i guess the preinciple(sorry about the spelling) is the same.

so in pusedo code

get value for array

save number of arrays first
save which array
save array length
save all type values one after another
save next array same as before

okay
i think i get it

cheers
Plugged


Work Hard; Play Harder ;
David R
21
Years of Service
User Offline
Joined: 9th Sep 2003
Location: 3.14
Posted: 20th May 2005 03:51
Yeah... the number of arrays is kind fo useless (because when loading them, you should know anyway) Yet.. keep it in, because the loading function depends upon it.

Anything your unsure of, just ask

(generating random values for the array was only for demonstration purpose by the way - so when you have an array full of values, you can skip that setp.)

[url=www.lightningstudios.co.uk][/url]
Plugged
22
Years of Service
User Offline
Joined: 30th Nov 2002
Location: Hertfordshire
Posted: 20th May 2005 04:19
okay just made this code could you check it that it would work i dont know if it will compile i haven't tried but can you check it can you like dry run it.

ohh and the load function would be in a different program but working on the same file as was saved by the save function



cheers
Plugged


Work Hard; Play Harder ;
David R
21
Years of Service
User Offline
Joined: 9th Sep 2003
Location: 3.14
Posted: 20th May 2005 04:24
Nice looking code- appears as though its along the same lines Pleased to of helped - but cant't test it at the moment (just whipping up a DBP audio compressor)....

Good luck!

[url=www.lightningstudios.co.uk][/url]
Plugged
22
Years of Service
User Offline
Joined: 30th Nov 2002
Location: Hertfordshire
Posted: 20th May 2005 04:28
thanks for the help i start code the rest of the editor thanks

cheers
Plugged


Work Hard; Play Harder ;
Philip
21
Years of Service
User Offline
Joined: 15th Jun 2003
Location: United Kingdom
Posted: 20th May 2005 06:54
... Philip hums contentedly to himself while doing his daily "late evening" perusal of the forums ...

Quote: "It sounds like you are using the Save Array command. Save Array is very limited in how it can be used. It's only good for 1 dimensional, non-UDT arrays. "


... the contented humming stops abruptly ...

What? Pardon, but is this actually true? What on earth is the use of a "save array" command if it only saves one dimensional non UDT typed arrays? I'm incredulous. You may as well name the command "save one dimensional arrays".

MIKE! I feel an extra functionality request coming on.

Philip

Cheer if you like bears! Cheer if you like jam sandwiches!
P3.2ghz / 1 gig / GeForce FX 5900 128meg / WinXP home
RiiDii
20
Years of Service
User Offline
Joined: 20th Jan 2005
Location: Inatincan
Posted: 20th May 2005 07:03 Edited at: 20th May 2005 07:03
Quote: "What? Pardon, but is this actually true?"

Heh, don't take my word for it. Try actually writing a function that will save a multi-dimensional array or a UDT array that is flexible enough to save any size, dimension, or UDT list. Can't be done as far as I've tried. Have to write the save array function specifically for the array; no flexibility (except size). I'd be happy with that functionality. But really, it's probably easier to include a flexible Save Array() function.

"Droids don't rip your arms off when they lose." -H. Solo
REALITY II
IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 20th May 2005 08:02
If your UDT's don't include strings, then you can do it now, with the help of ... tada ... my array plug-in

You can get the address of each item within the array using the GET ARRAY ITEM PTR function, and you can get the size of each item using the GET ARRAY ITEM SIZE function. Once you have those, a bit of peeking and poking of memory byte by byte will allow you to read and write array items directly.


I've done some work on automating this and including strings into the mix, but it's not really ready for release, because it uses a minor hack which really belongs within the compiler
Still, there are lots of other goodies that this opens up too.

I've also got some other stuff that may allow the correct code to be generated in future for loading & saving, and that's what I'm playing with right now.

*** Coming soon - Network Plug-in - Check my site for info ***
For free Plug-ins and source code http://www.matrix1.demon.co.uk
Philip
21
Years of Service
User Offline
Joined: 15th Jun 2003
Location: United Kingdom
Posted: 20th May 2005 09:06 Edited at: 20th May 2005 09:06
Quote: "If your UDT's don't include strings, then you can do it now, with the help of ... tada ... my array plug-in"


IanM, I love you and I want to have your babies.

Philip

PS: Relax, I'm joking. Sadly my arrays do include strings.

Cheer if you like bears! Cheer if you like jam sandwiches!
P3.2ghz / 1 gig / GeForce FX 5900 128meg / WinXP home

Login to post a reply

Server time is: 2025-06-04 17:52:50
Your offset time is: 2025-06-04 17:52:50