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 / How do you look for a number in a file

Author
Message
negi
13
Years of Service
User Offline
Joined: 16th Feb 2011
Location:
Posted: 2nd Oct 2011 06:21
Hi I am trying to make a class that will first create a file, then when I load a new image into the game it looks into that file and reads what image numbers are already used. Then it will assign that image a number one higher than the highest number in the file. Can anyone please help me out with a way to go about solving this?

All is revealed with time.
Hassan
15
Years of Service
User Offline
Joined: 4th May 2009
Location: <script> alert(1); </script>
Posted: 2nd Oct 2011 14:56
why would you do this when you can store the number in a variable:
?

negi
13
Years of Service
User Offline
Joined: 16th Feb 2011
Location:
Posted: 2nd Oct 2011 22:12
I am trying to write a class that handles all of that for me so I don't have to remember what numbers I have or have not used. A file is the best way I can think of unless you know of a better way!

All is revealed with time.
Dar13
16
Years of Service
User Offline
Joined: 12th May 2008
Location: Microsoft VisualStudio 2010 Professional
Posted: 2nd Oct 2011 22:42
An array, std::vector<int>, or even an std::map<const char*,int> would be better than using a file to keep track of the individual image numbers.

To get the highest number, I would just use a counter variable in the class.

Example:

Might not be valid C++, but it demonstrates my point.

Mr Bigglesworth
16
Years of Service
User Offline
Joined: 4th Mar 2008
Location:
Posted: 3rd Oct 2011 00:33 Edited at: 3rd Oct 2011 00:43
Here:


Put that code in "ResourceManager.h". Those 2 classes handle all management of ID's for any resource you want.

To use it put this at the top of your main code file after you include "ResourceManager.h"


And to create a image do this:


And to delete and image do this:


"IMAGENAME" can be anything you want to call the image.

The classes can also tell you the used, unused, and total ID's in your program. It is a very useful thing to have if you are making a large game.
Dar13
16
Years of Service
User Offline
Joined: 12th May 2008
Location: Microsoft VisualStudio 2010 Professional
Posted: 3rd Oct 2011 02:31
Mr. Bigglesworth, that is a very comprehensive index-manager and resource manager combination.

The only flaw I can see with it is that you would need a ResourceManager object for each DarkGDK element that needs an ID.

Mr Bigglesworth
16
Years of Service
User Offline
Joined: 4th Mar 2008
Location:
Posted: 3rd Oct 2011 02:54 Edited at: 3rd Oct 2011 02:55
Quote: "Mr. Bigglesworth, that is a very comprehensive index-manager and resource manager combination.

The only flaw I can see with it is that you would need a ResourceManager object for each DarkGDK element that needs an ID."


It was originally written by TechLord, and when I finish up some gameplay elements I plan to modify it a little to suit my game better.
negi
13
Years of Service
User Offline
Joined: 16th Feb 2011
Location:
Posted: 3rd Oct 2011 06:06
Wow that's great thanks so much!

All is revealed with time.

Login to post a reply

Server time is: 2024-10-02 19:21:37
Your offset time is: 2024-10-02 19:21:37