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 / Write Custom Type to File

Author
Message
His Imperial Majesty
18
Years of Service
User Offline
Joined: 19th Sep 2007
Location: Throne World of Korhal
Posted: 5th Jul 2011 02:15
Hi all,

I apologize for my ignorance if this has been discussed before but I can't seem to find anything that strictly addresses this.

I think I get the gist of file i/o but what I'm wondering is is there any way to write/read a custom type to a file? Say, for example, I want to store the state of the items stored within an item inventory every time the player saves his game. An item being defined as:



I know I could just do:


The above is fine in that it stores all the relevant data to any specific Item within items(). But say I have an Item called FragGrenade:



If I was to read the data stored to save.dat it would give me all the fields but not the FragGrenade pointer (FragGrenade.whatever).

How, then, can I reload the data from items() and still have a Item be the same type as it was stored? Or, better yet, is there a way to directly store a custom type?
Neuro Fuzzy
19
Years of Service
User Offline
Joined: 11th Jun 2007
Location:
Posted: 5th Jul 2011 04:50
Quote: "If I was to read the data stored to save.dat it would give me all the fields but not the FragGrenade pointer (FragGrenade.whatever).
"

I have no clue what you mean by this.

Quote: " Or, better yet, is there a way to directly store a custom type? "

I believe IanM's matrixutils has a command called "Save Array" which takes into account UDTs. (There's a built-in one that can't handle UDTs I think)


Why does blue text appear every time you are near?
His Imperial Majesty
18
Years of Service
User Offline
Joined: 19th Sep 2007
Location: Throne World of Korhal
Posted: 5th Jul 2011 05:00
Quote: "I have no clue what you mean by this. "


Sorry, I'm rather bumbling when it comes to explaining myself. I'm trying to store Items in items() so that when a player loads his save, all of the proper Items that had been in the inventory before will still be there. I can store the fields of an Item no problem but then how can I have it be so that whatever Item is at items(x) is understood to be of its correct sub-Item type, whether it be a FragGrenade or a HealthPack or an AmmoClip?

I had briefly looked at IanM's matrixutils but I must've not seen the UDT functionality. I'll take a second look, thanks.
His Imperial Majesty
18
Years of Service
User Offline
Joined: 19th Sep 2007
Location: Throne World of Korhal
Posted: 5th Jul 2011 07:13
Alright, so it looks like IanM's stuff will work for me. I'm having trouble installing the plug-ins though. I extract them to the appropriate folder but when I open up the editor, they don't appear in the plug-in manager. Did I do something wrong?
IanM
Retired Moderator
23
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 5th Jul 2011 15:13
Most probably, yes.

Don't drag-n-drop the files, as sometimes that will 'flatten' the directory structure within the zip. Do a proper extract and that will maintain the directory structure, and that will put everything into the correct place.

His Imperial Majesty
18
Years of Service
User Offline
Joined: 19th Sep 2007
Location: Throne World of Korhal
Posted: 5th Jul 2011 17:59
You read the situation quite correctly. I was getting some weird "Access Denied" error from WinRAR but I looked into it more fully today and was able to get rid of it. I extracted the files to the DBP folder with WinRAR but I'm still not getting anything showing in the plug-in manager. :/
Rich Dersheimer
AGK Developer
17
Years of Service
User Offline
Joined: 1st Jul 2009
Location: Inside the box
Posted: 6th Jul 2011 00:43
The plugin manager is for showing plugins for you editor, not for DBPro. Your editing environment doesn't have any plugins, so you won't see any listed. If you have extracted the keywords file to the correct location, the first time you run the editor after that, it registers the keywords, but may have happened too fast for you to notice.

A quick way to see if you have IanM's utils installed is to try this command...



Ian's ink command doesn't require a second parameter, but the DBPro command does require a second parameter. If it compiles, then IanM's stuff is available to you.

Good luck!

IanM
Retired Moderator
23
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 6th Jul 2011 00:59
Ah, is that's what's going on?

Just as easy, and you need to do this anyway, is to rebuild the keywords list (Tools->Rebuild Keywords). Then when you type in one of my commands (such as MAKE BANK), it will highlight as a keyword.

His Imperial Majesty
18
Years of Service
User Offline
Joined: 19th Sep 2007
Location: Throne World of Korhal
Posted: 6th Jul 2011 01:38
Ah. That works wonderfully. My thanks to you gentleman for your help.

Login to post a reply

Server time is: 2026-07-10 21:41:49
Your offset time is: 2026-07-10 21:41:49