Jump to content
  • Advertisement

665.999

Member
  • Content Count

    8
  • Joined

  • Last visited

Everything posted by 665.999

  1. Hey everybody! I'm using Visual Studio 2010 (Visual C++) and Allegro 5.0.4. After following the first tutorial, and getting an error, and then following the second tutorial, and getting the same error, I figured I'd ask why this is happening and if I can get help on fixing it. Tutorial 1: http://wiki.allegro.cc/index.php?title=Windows,_Visual_Studio_2010_and_Allegro_5 Tutorial 2: http://fixbyproximity.com/2011/07/2d-game-dev-installing-allegro-5-with-visual-studio-2010/ The error: When I run either of the test builds in these tutorials, the black consol window will open up. Then, the debug window will start glitching out in my task bar below, sliding along down the task bar for no reason, fading in and out, and then the will stop and say: "Unhandled exception at *hex number* in AllegroTest.exe: *hex number*: Access violation reading location *hex number*. It then opens up a crtexe.c code file for some reason. If anyone can help me get Allegro to work properly, that would be awesome. Thanks so much!
  2. Hi Everybody! I'm new to C++ and I'm trying my most ambitious project yet; an RPG styled text version of Resident Evil 3. I'm having problems with creating an item though. Let's say we have item HandGunAmmo. I create a struct in the header file "Items.h" called GunAndAmmo. I have an int variable declared called InvAmount. I then create an instance called HandGunAmmo. I create a function called void DeclareAllItems(), that I use to make sure all the items values start at 0. Therefore, HandGunAmmo.InvAmount = 0. We have 0 Handgun Bullets. So far this has worked in my program. However, when I try and create the battle loop and include the "Items.h" file, it says; "Multiple definition of DeclareAllItems()" "Multiple definition of HandGunAmmo" What I want to do is create an int value starting at 0. As you go through the game, you can find ammo (therefore increasing the value). When you battle and use bullets, it decreases the value. However it won't let me access the variable again to modify it. At any point in the game I need to be able to access this variable so the player knows how much bullets he has, And when he starts a battle, he begins with the amount of bullets he has had up until that battle. Should I be using a pointer to point at HandGunAmmo.InvAmount? Should I not be declaring it in a struct, instead declaring it as a global variable? Any help is very useful and appreciated. If any more info is needed, I am happy to share it (even uploading all the source code). Thanks for your time guys . Edit: The reason I am not just posting my source code right away is because I want to try and understand the possible concepts I am getting wrong, not the code. I am doing pretty good at coding, but sometimes the concepts are hard to grasp (especially Classes atm). So if I shouldn't be using a structure or should be using a pointer or whatever the problem is, I'd rather find out conceptually what I'm doing wrong then just being handed the code .
  3. 665.999

    Problem creating an item in Text Game

    Thanks a lot for the suggestions guys! I tried declaring it in main instead of Func1, and I tried passing Player as an argument. It still comes up with the same error "already defined". Outside of the code, how would you guys go about doing this? On a high level, I mean. If you had an integer you need to be able to access inside every function in your entire program (ie. in an RPG, you need to be able to see your HP in battle and in your menu and adjust your HP, during battle and using items in your menu etc.), how would you go about implementing that in your program? Maybe I'm trying to do it in a wrong way and there's a better solution?
  4. 665.999

    Problem creating an item in Text Game

    I create Player in Func1(), CHRCTR Player; I then also call methods of Player in the Func1 Function, and in Main after Func1 is over.
  5. 665.999

    Problem creating an item in Text Game

    Thanks pulpfist! Now the only problem is that it says "class CHRCTR Player already defined", since I'm calling the Player.setHGBA() method both in the Func1 and Main functions (or at least I think that's why). I want to be able to change the HGBA variable at any point of the program, so is there a different way I should be doing this or is there some code I'm missing/doing wrong?
  6. 665.999

    Problem creating an item in Text Game

    Thanks for the replies! I've switched to Visual Studio 2010 as my C++ Compiler, thanks for the suggestion . So from what I gather from the links to info on inclusion guards, I should change the Class.cpp file to Class.h with inclusion guards, like so: /* **CLASS.H*** */ #include <iostream> using namespace std; #ifndef CLASS_H #define CLASS_H class CHRCTR { private: int HGBA; // the amount of HGBA public: int getHGBA(); // Should be able to get how much I have? void setHGBA(int); // Should be able to set how much I have? }; void CHRCTR::setHGBA(int bullamount) { HGBA = bullamount; } int CHRCTR::getHGBA() { return HGBA; } #endif // CLASS_H Edit : I've edited my post above with my source code to match what I currently have on my 'updated (but still not working)' file. However, it still doesn't work, and I get the same "already defined" errors. If there are any more tips to offer, please let me know . This is the main thing holding me back from finishing my text based game!
  7. 665.999

    Problem creating an item in Text Game

    Hey guys, thanks for the replies. I'm reading up on the links you have suggested to me. Here is a basic version of the code (without all the plot and whatnot of the text game I'm making) so you can see the basic issue. It comes up with the same compiling problems. HGBA = HandGunBulletAmount. My compiler is Dev-C++. Thanks for your time . Edit: This text has been motified from what I've learned from comments below, but it is still not working. I have changed my compiler to Visual Studios 2010. The error I am getting is "already defined". ****MAIN.CPP**** #include <iostream> using namespace std; #include class.h void Func1(); // Declaring the prototype from the other file. This is where the story would start int main() { Func1(); // Send it to the FUNC1.CPP where I can start the game Player.setHGBA(20); // I should be able to change the value after Func1, or anywhere else I want to in the game and source code system("pause"); return 0; } ****FUNC1.CPP***** iostream, namespace std etc; #include "Class.h" // Include the class that holds HGBA void Func1() { CHRCTR Player; Player.setHGBA(10); // start the player's amount at 10 cout << Player.getHGBA() << endl; // test to see if I can see that the HGBA amount is 10 } ***CLASS.H**** iostream, namespace etc... #ifndef CLASS_H #define CLASS_H class CHRCTR { private: int HGBA; // the amount of HGBA public: int getHGBA(); // Should be able to get how much I have? void setHGBA(int); // Should be able to set how much I have? }; void CHRCTR::setHGBA(int bullamount) { HGBA = bullamount; } int CHRCTR::getHGBA() { return HGBA; } #endif // CLASS_H
  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!