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.

Dark GDK / Ludo's Data Management Methodology

Author
Message
Ludo
16
Years of Service
User Offline
Joined: 23rd Jun 2008
Location: UK, Oxfordshire
Posted: 9th Jul 2008 21:56 Edited at: 9th Jul 2008 22:19
Greetings! The following is my entire method for saving and loading data in and out of a running program.

Firstly, I’m using the method for saving and loading information in and out of my RPG, so asides from the fact that this isn’t all I will be using during the entire program’s flow, I built it with the idea in mind that it will be used within an RPG to handle character data so the method might not be applicable to all game genres and a different method might work better for you. However the actual code will work regardless so if you need to know how to save and load data in and out of your program this might help.

K, first thing I did was to make a class with a set amount of data elements which I know will make up all my world objects, not just world characters but everything. I did this because all objects within my world are going to be treated as world characters and interact using a unique statistical character interaction system called Ability Based Character Development (ABCD), which I created to, in short, blow D20 out of the water.

Alright, every aspiring RPG games designer makes that claim so ignore that bit if you want but that is why I did it this way.
Anyway, the class I created is as follows:



This contains the basics character data which I have come up with thus far:



Right then, the next thing I did was create the Maestro class which currently holds the functions for creating and loading objects into the world:



The create object function takes in an object type object from the main, the world characters Name and ImageSet. It then sets the object’s name varible to the name arguement and the Imageset is set likewise. I am using a ripped sprite from Ragnarok Online as an image marker as I would like it’s graphics on my game eventually.

The imageset of “Mage” sets ImageName1 to “Mage.bmp” which allows the following function within Maestro to load the image into the program. The other varibles of the passed object are simply set to 0 as most of them either aren’t used or need setting to 0 at this point.

The load object function takes only one arguement; the same object from the main. It uses the values set by the create object function to make the sprite. Of course if the object object from the main is set to different values by the load command then it can load a saved object.

Alright, now for the good stuff:



The code above creates all the objects which are used during saving and loading within the program. One fstream for saving and loading data, one Maestro for creating and loading objects (see above) and one object of type Object by name of Player which is designed to handle all of the world characters by way of loading and saving of player data from saved files.

I like the names of these personally. If you don’t get it, check the meanings of ‘Scribe’ and ‘Deus’ (Deus Ex Machina) and then check their functionality.



The above simply initilizates each object becuase I declare my objects as pointers. Not sure why, it’s just the way I learned to do stuff.



This is my global varibles list which contains the data location (loc) array which is used later to find data elements within the extracted datafile, the buffer (buf) multidemenshional array used to store the data elements post extraction, two for loops for voiding both loc and buf and finally two varibles for setting the size of memblock to the size of the data file and for containing the data from the datafile after extraction.
Alright then, first you call this:



To set the contents of the player object to nothing...alright SpriteNumber is set to 1 but that dosent really matter.



You then call this to create the basic structure of a player, in this case it’s name is Ludovic and the image set it should be using is ‘Mage’.



This lot still needs putting into a function but I am currently looking for a way to simplfiy it into a loop or something or at least make it a bit shorter. It’s basic function is to create and open a file named Ludovic and write to it all the different factors about a player character from it’s name to world position and stats. What it gives you is a file which looks like this that can be accessed with notepad:



You will see why is formtted like this a second.



The first line opens the Ludovic file by the simple expident of using the characters name. I plan on changing this to a character reference number later though but it will work exsactly the same way.

The next three lines just gets the file size, set memblock to that file size and then transfer the contents of the file into the memblock char*. The file is then closed. The for loop, which runs the same number of times as the quantity of data elements minus 1 becuase arrays start at 0 not 1, scans how many characters are sitting between each ‘¬’ character and places it’s contents into a slot on the multidemenshional char* buffer array, one layer of 30 characters for each slot on a Object Object, most of which won’t ever equal 15 and can be limited quite easily.

After the for loop the data stored within the buffer multidemenshional char* is transfered into the relevent slots on the Object class object, i.e. Player.



The maestro function Load_Object can then use the data stored within Player to actually create the object. Then with...



You can move the object around be editing the X and YPos varibles on the Player Object and calling the sprite command. If you then reuse the save command to save the updated X and YPos you can then deleate the object from the game world thus...



...And then void the player object, reload the updated saved data back into player, call the load object maestro function again and get the character back into the game world in the same position it was in previously.

Using this method you could create loads of objects and characters with the same set of stats and control varibles within something like a map maker and then use game specfic functionality to control what those characters do and respond to within the game world.

Currently I’m now working on creating an second object for the first to collide with and reorganising the movement functions and that. Afterwards I can move onto implementing my ability based character development system using the above method for storing object and character data. Of course the above will need a lot of reorganization and placement into a User Interface designed to manage the stored files but I don’t see that as being a problem.

...If I’m not mistaken I think they used this method for making the monsters in Spore too...sheer accident that mines the same...*shrug*.



We are here and it is now.
Benjamin
21
Years of Service
User Offline
Joined: 24th Nov 2002
Location: France
Posted: 9th Jul 2008 23:02 Edited at: 9th Jul 2008 23:07
Quote: "if ( Obj->ImageSet == "Void" )"

I would just like to point out that you technically can't do this. You're just comparing two pointers, not the data they point to. Use strcmp or memcmp.

Ludo
16
Years of Service
User Offline
Joined: 23rd Jun 2008
Location: UK, Oxfordshire
Posted: 9th Jul 2008 23:18
What are you talking about, ImageSet is a char* variable and void is a set of characters. Where’s the other pointer?

We are here and it is now.
Benjamin
21
Years of Service
User Offline
Joined: 24th Nov 2002
Location: France
Posted: 9th Jul 2008 23:24
Quote: "What are you talking about, ImageSet is a char* variable and void is a set of characters. Where’s the other pointer?"

"Void"

Ludo
16
Years of Service
User Offline
Joined: 23rd Jun 2008
Location: UK, Oxfordshire
Posted: 9th Jul 2008 23:28 Edited at: 9th Jul 2008 23:29
Yes that is four characters...not a pointer.

Anyway, your wrong because the program works fine and does its function if that variable is "Void" so...shut up.

We are here and it is now.
Benjamin
21
Years of Service
User Offline
Joined: 24th Nov 2002
Location: France
Posted: 9th Jul 2008 23:34
You've got a great methodology there where if it works there and then at the time, then it's the correct way of doing it. Well if you continue like that, you won't be a successful programmer.

I can tell you know that you do not know as much as you think you do, yet you seem quite sure that you do.

Yes that is four characters, but it's accessed by pointer. When you assign it to something, you're assigning a pointer, not the four characters that are inside the quotation marks.

Now, I would really suggest you go read a C++ tutorial from the ground up and stop treating the language like it's DBP.

Zuka
16
Years of Service
User Offline
Joined: 21st Apr 2008
Location: They locked me in the insane asylum.
Posted: 9th Jul 2008 23:37 Edited at: 9th Jul 2008 23:39
Quote: "Now, I would really suggest you go read a C++ tutorial from the ground up and stop treating the language like it's DBP."


Owned.

I read an 800 page C++ book, and reread the pointers section 3 times. I still barely understand them, but I can use them... somewhat.

Benjamin, wouldn't it be a const char[4]? Oh... no. It'd be const char*.

Kentaree
21
Years of Service
User Offline
Joined: 5th Oct 2002
Location: Clonmel, Ireland
Posted: 9th Jul 2008 23:42
Ok, to explain what Ben is saying, take this for an example:

char* message = "Void";

Put that in a compiler, compile it, and see that it works. That's because behind the scenes, C++ creates an array of characters, and issues a pointer to the first character.

Now, do the same again, but with a different variable:

char* message2 = "Void";

The same process is repeated again, only the same text is now in a different memory location, try and print out the address values of both vars using something like

printf("Message: %d, Message2: %d,message,message2);

Now unless your C++ optimises at compile time and uses a string pool like java does, the memory locations will be different. So, comparing message to message2 will result in an inequality. I hope that explains it a bit, if not, meh.

Benjamin
21
Years of Service
User Offline
Joined: 24th Nov 2002
Location: France
Posted: 9th Jul 2008 23:44
Quote: "Benjamin, wouldn't it be a const char[4]? Oh... no. It'd be const char*."

Correct (the former).

Ludo, let me prove it to you:



Kentaree, what you're saying can generally be true (there's no rule saying two matching constants have to share the same space), although sometimes compilers automatically do string pooling in some cases, even with it turned off.

Ludo
16
Years of Service
User Offline
Joined: 23rd Jun 2008
Location: UK, Oxfordshire
Posted: 9th Jul 2008 23:47 Edited at: 9th Jul 2008 23:48
Firstly I am a games designer, not a programmer. I am not trained to understand the in's and out's of c++. I am trained to understand the systems and processes I create. I have created game systems which move abstract modules of data around which work like a well oiled machine. Now I am trying to make a game out of them.

I have not and will not claim to be a great programmer because I am not a programmer, I am a games designer.

Secondly I am very sure of everything unless someone points of the converse. See my sig, "We are here and it is now." It means that I believe entirely what is directly before me until it is proven false. This system works, ergo I will use it until it breaks down and then fix it or else I see a problem with it.

Thirdly is it accessed by a pointer, that I did not know, you should have said something.

I have never used DBP, I am learning c++ as I go and don't tell me what I should and shouldn't be doing you little twerp.

Now, remain civil or I will ignore you because you don't have to post here and for that matter, the shut up comment was a joke.

We are here and it is now.
David R
21
Years of Service
User Offline
Joined: 9th Sep 2003
Location: 3.14
Posted: 9th Jul 2008 23:56 Edited at: 9th Jul 2008 23:58
Quote: "I have never used DBP, I am learning c++ as I go and don't tell me what I should and shouldn't be doing you little twerp."


Yes, that's precisely the attitude to take.

Rather than being humble and/or accepting of corrections, you have to be provocative and darn right rude to those who are trying to assist you... and then you wonder why you receive rude or inflammatory remarks?

Just take it as it comes. You're not an expert at C++. Neither are most of the people here. But if you're posting here for assistance etc. then accepting some advice is not exactly hard to do. Yes, of course you can reject bad advice if you have good grounds to do so. But a very large majority of us have offered (and will continue to offer) useful, constructive advice. When a response turns the tone sour, however, the bluntness of our posts will undoubtedly increase as you've seen - we love C++, we eat sleep and breath C++, so anyone saying "no" to well known facts about our beloved language is akin to heresy, and we react accordingly.

Accept advice. Question what you're told, but question it constructively, rather than just saying "XYZ is wrong, you don't know what you're talking about"


09-f9-11-02-9d-74-e3-5b-d8-41-56-c5-63-56-88-c0
dark coder
21
Years of Service
User Offline
Joined: 6th Oct 2002
Location: Japan
Posted: 9th Jul 2008 23:59
Quote: "Secondly I am very sure of everything unless someone points of the converse."


Yet in these two threads many people have been telling you the converse and yet you don't listen to them despite them having many years of experience in multiple programming languages and having worked with the things you're having issues with far far longer than you have?

Quote: "This system works, ergo I will use it until it breaks down and then fix it or else I see a problem with it."


This is a very bad philosophy to work by, especially in programming. Just become something works on your computer at that time doesn't mean it will for everyone all the time, just a simple glance at the code should tell any average user what the issue is, and they would fix it right? So you're saying even if you knew the issue you'd only fix it if you saw someone had an issue while using it? You see no problem with this?

Quote: "I have never used DBP, I am learning c++ as I go and don't tell me what I should and shouldn't be doing you little twerp."


Why shouldn't he? You've done nothing but ignore all the good advice the people have written here, even quick google searches will find loads of information about this and I doubt you're the first to have a string based problem in C++. It's clear by your code that you don't fully understand how c-style strings work at all so following a tutorial on them would be most beneficial(or does your PC need to blow up before you'd see the need to read one?).

Quote: "Now, remain civil or I will ignore you because you don't have to post here and for that matter, the shut up comment was a joke."


Sure he doesn't have to post, why do any of us have to post here? Clearly you're the master at C++ and know everything, why do we have to bother helping you at all, good luck getting any further help with this attitude.

Ludo
16
Years of Service
User Offline
Joined: 23rd Jun 2008
Location: UK, Oxfordshire
Posted: 10th Jul 2008 00:33 Edited at: 10th Jul 2008 00:36
Benjamin - Alright, I ran the thing in release, it crashed when it tried to run the write functionality and I fixed it with strcmp, you were right, I was wrong, I apologize...long day, sorry. *shrug*

I'm currently testing it to see if there is anything else like that but seriously, I'm not going to release the thing without testing it first and it's not like I can't debug a c++ program so don't say stuff like 'you don't know as much as you think you do' and that because some people react ballisticly to stuff like that. I mean I've got a uni degree and that so it's not like I'm an idiot. And I know when to admit I'm wrong, so I am sorry and if you have any further advice I will listen and not explode when provoked.

David R - Dude, when I say stuff like that I am joking...ok that isn’t obvious in text I admit but where I come from people greet each other with "Hey A**hole" which might tell you why my social abilities tend towards insults with on the end of them. Sorry. *shrug*

We are here and it is now.
Mahoney
16
Years of Service
User Offline
Joined: 14th Apr 2008
Location: The Interwebs
Posted: 10th Jul 2008 00:35
Quote: "I mean I've got a uni degree and that so it's not like I'm an idiot."


Ah, but a degree in what? That's more important than just having it.
Ludo
16
Years of Service
User Offline
Joined: 23rd Jun 2008
Location: UK, Oxfordshire
Posted: 10th Jul 2008 00:44
dark coder - That’s not entirely fare. I have listened and read and then questioned. Alright it might not have been entirely...respectful maybe but I haven’t ignored what I’ve been told.

No, I just don’t like or trust people at all and believe me, I have good reason. From my prospective, everything works and if it doesn’t I find out about it not working sooner or later via testing and fix it then. I am not a master at c++ but I am persistent and intensive; every error comes out sooner or later and is fixed.

Also, in the other thread, if someone had posted what Lil did then the problem would have been solved on the first page so it’s not entirely accurate to say everyone is providing perfect advice is it.

Mahoney - Computer Games Technology, Majoring in Games Design, second in programming, hence my basic knowledge of c++ and my expert claim to games design.

We are here and it is now.
Mahoney
16
Years of Service
User Offline
Joined: 14th Apr 2008
Location: The Interwebs
Posted: 10th Jul 2008 00:59
I don't mean this disrespectfully, but I must ask: after a university class on programming, you thought that you could compare strings with ==? o.O
Ludo
16
Years of Service
User Offline
Joined: 23rd Jun 2008
Location: UK, Oxfordshire
Posted: 10th Jul 2008 01:10
Yeah, I didn't do some of it and forgot a lot in-between the time I was designing the game I'm now building. I don't like programming very much but a demo is 'The Thing' to have in your CV so. *shrug*

We are here and it is now.
Mahoney
16
Years of Service
User Offline
Joined: 14th Apr 2008
Location: The Interwebs
Posted: 10th Jul 2008 01:13
Oh. That makes sense.

Personally, I love programming. I hate that I'm not better at it. I know tons of info about how it works, but can't structure things well. :/
Ludo
16
Years of Service
User Offline
Joined: 23rd Jun 2008
Location: UK, Oxfordshire
Posted: 10th Jul 2008 01:16
I'm the opposite. I build the systems structure excellently, but I don't pander to one's created by others like c++.

We are here and it is now.
dark coder
21
Years of Service
User Offline
Joined: 6th Oct 2002
Location: Japan
Posted: 10th Jul 2008 01:29
Quote: "Also, in the other thread, if someone had posted what Lil did then the problem would have been solved on the first page so it’s not entirely accurate to say everyone is providing perfect advice is it."


Sure it is, Lilith merely gave you the exact answer, I told you what was wrong with the code and how to fix it, leaving you to do the actual code, so you have to do some work.

Mahoney
16
Years of Service
User Offline
Joined: 14th Apr 2008
Location: The Interwebs
Posted: 10th Jul 2008 01:30
I'm getting a little better, but, I haven't had a college class on it.
Zuka
16
Years of Service
User Offline
Joined: 21st Apr 2008
Location: They locked me in the insane asylum.
Posted: 10th Jul 2008 21:52 Edited at: 10th Jul 2008 21:54
Quote: "we eat sleep and breath C++"


Wow, how'd you know? I fell asleep reading my C++ reference book!

Ludo, if you're going to call one of this forum's brightest people a twerp, then you just need to go away. If you're going to act like that, we do not want you around. This is a nice and friendly community. I don't want someone with your attitude fouling it up.

Zuka
16
Years of Service
User Offline
Joined: 21st Apr 2008
Location: They locked me in the insane asylum.
Posted: 10th Jul 2008 21:55
Mahoney, I have an idea. Can you get on Yahoo/MSN or whatever so we can discuss it?

Mahoney
16
Years of Service
User Offline
Joined: 14th Apr 2008
Location: The Interwebs
Posted: 10th Jul 2008 22:00
Yeah. I can get on MSN. However, it will have to wait until later. Is that alright? I'll be busy for the next 5-6 hours.
Zuka
16
Years of Service
User Offline
Joined: 21st Apr 2008
Location: They locked me in the insane asylum.
Posted: 10th Jul 2008 22:03
Mahoney
16
Years of Service
User Offline
Joined: 14th Apr 2008
Location: The Interwebs
Posted: 10th Jul 2008 22:04
Sorry. About 7 or 8 I'll be able to talk. Maybe sooner.
Zuka
16
Years of Service
User Offline
Joined: 21st Apr 2008
Location: They locked me in the insane asylum.
Posted: 10th Jul 2008 22:08
Cool. You're working on a 2D RPG, right? That's it?

Mahoney
16
Years of Service
User Offline
Joined: 14th Apr 2008
Location: The Interwebs
Posted: 11th Jul 2008 02:22
I'm able to talk now. I'm signed in with the Windows Live account under mmahoney62292@gmail.com

Login to post a reply

Server time is: 2024-09-30 01:23:26
Your offset time is: 2024-09-30 01:23:26