![]() |
OT: Stupid c++ (Roguelike development)
So I'm trying to declare a vector. It declares fine in the main function. The only problem is, I need to declare it in one of the header files. Except that if I try to declare it in function I want to use it in in the header file, it tells me that ' `vector' undeclared (first use this function)'.
If I try to declare it outside the function, it tells me that 'expected constructor, destructor, or type conversion before '<' token' So it seems like my header file can't access the vector code or something. |
Re: OT: Stupid c++
Assign them different names, and pass the value of one to the other.
|
Re: OT: Stupid c++
That still doesn't fix the fact that I can't declare vectors in the header and the header is where I need to declare the vector.
|
Re: OT: Stupid c++
Vector isn't a built-in type, so you need to have something, typically in the header file, like:
#include <vector> and probably you want: using namespace std; and then to declare it, something like: vector <MouseCheeseWhatever> NarfsVector; |
Re: OT: Stupid c++
Much thanks.
|
Re: OT: Stupid c++
Would anyone happen to know why the computer would lock into 'drag and select' mode, generally requiring me to do a complete shut-down?
That's any part of the computer capable of 'drag and select' gets locked into that mode. It sometimes happens when I'm dragging and selecting. |
Re: OT: Stupid c++
Sounds like your mouse button is getting stuck in a down position, or software (mouse driver, or some program messing with mouse messages in a bad way) is messing up the mouse. Like, saying it has handled the MouseUp message and not passing it on to other software, so other programs don't see the MouseUp event so it's like your mouse button is stuck down.
|
Re: OT: Stupid c++
I think it's my keyboard - Tapping the shift key has helped twice now, so it's probably dying.
The mouse is only about 6+ months old; can't remember when we got the keyboard, but it's outlasted at least two processors, I think. |
Re: OT: Stupid c++
What does 'expected primary-expression before '.' token' mean? I'm trying to make a pointer for a base class equal to one of its derived classes.
Thanks again. |
Re: OT: Stupid c++
Ah, the joys of dereferencing.
. is used to access members of an object. -> is used to access members of an object when you have a pointer to that object. If you have: object* MyObjectPtr = new object(); then you have to access members via: MyObjectPtr->member(); Whereas if you have just: object MyObject; you use: MyObject.member(); |
Re: OT: Stupid c++
Erm, the pointer is one of the variables in the base class. I'm restarting the roguelike project, only mucho simpler.
The relavent lines: Quote:
|
Re: OT: Stupid c++
*Whaps forehead*
Must remember...A class is *Not* a variable. Must declare class as variable first. Well, at least I changed the error...Er, never mind. Putting '&' in front of what I wanted to convert fixed it. And now it all works. Or seems to. Can never tell with those programs. *Darting eyes* Sneaky programs. |
Re: OT: Stupid c++
I'm getting aa '[Linker error] undefined reference to `vtable for Character' '
Ok, so it doesn't like virtual functions without a '{};', even if they are void. |
Re: OT: Stupid c++
Got a dungeon, got doors that open and close, got an intermitent glitch in the dungeon algorithm...
Would anybody know how to turn on Dev c++'s Debug mode? I'm getting nowhere with 'F8'. |
Re: OT: Stupid c++
Ehm ...
Why don't use Phython? Or, at least, Java? Or, if you love M$, C#? I programmed 10 years in C and C++ and it's an headhache. |
Re: OT: Stupid c++
This explains all the nomenclature in your posts! http://forum.shrapnelgames.com/images/smilies/laugh.gif
|
Re: OT: Stupid c++
Don't suppose it happens to be an SE4-themed roguelike does it?
The Phong wields a hand cannon --more-- The Phong fires at you --more-- You die That would be cool... |
Re: OT: Stupid c++
Yeah, I wanted to do an SE module for Dungeon Odyssey once, but it never got anywhere... DO seemed a bit tricky to mod, and I couldn't figure out where to start with the concept anyway http://forum.shrapnelgames.com/image...ies/tongue.gif
|
Re: OT: Stupid c++
Python is interpreted, java is interpreted, I have an aversion to M$-only projects.
No, just a simple dungeon-based one. I would perfer this thread not go off-topic before I get an answer. |
Re: OT: Stupid c++
What's a good, simple way to get the console to ignore the mouse? I'm using this: http://www.adrianxw.dk/SoftwareSite/index.html for events.
|
Re: OT: Stupid c++
I'm not familiar with "Dev C++" - never even heard of it, sorry.
What response to mice are you getting that you don't want? One thing you can generally do is handle mouse events received by your window, and then just do nothing with them and say you handled it. But that's assuming you have a window procedure. If you're running in an MS-DOS-like Windows console window running as a console app, then I don't think you do control how that window behaves - it's a window from Windohs onto your program's i/o. You might be able to make a Windohs shortcut to your app and play with the shortcut's settings to alter the mouse behavior - I'm not sure how many options you have to do that, though. What's the mouse doing that you don't want it to? |
Re: OT: Stupid c++
Oh, I just glanced at the code you linked to, and saw this:
<font class="small">Code:</font><hr /><pre> case MOUSE_EVENT: ++MouseEvents; SetConsoleCursorPosition(hOut, MouseWhere); cout << MouseEvents << flush; break; </pre><hr /> Is that in your code? Is that what's doing what you don't like? Looks like it is set to move your cursor wherever the mouse goes. If so, just comment out (or delete) all the lines above, to stop it doing that. |
Re: OT: Stupid c++
*Whaps forehead* Yeah, it works much better when I describe the problem. Sorry.
Basically, each time I move the mouse...Er, the characters used to flicker. Something I did stopped that, though...Programs is wierd. |
Re: OT: Stupid c++
How would one convert an int into a std::string?
Programs for debugging...What can you tell me? |
Re: OT: Stupid c++
For that matter, how would one convert a std::string into an int? Or a float?
Are there any libraries out there for this? |
Re: OT: Stupid c++
http://www.cplusplus.com/ is a decent source of c++ info. Look up atoi. Then recall that string objects have a .c_str() member function that will return a c-style string (null-terminated array of characters).
There is a function to go the other way, but I forget it. Debugging is related to the compiler you are using. What is your compiler? |
Re: OT: Stupid c++
Thanks. If all else fails...
Dev c++ - The debug function doesn't seem to work. Is it possible to use the '>>' operator with an 'ifstream'? |
Re: OT: Stupid c++
Can someone give me an example of how to use seekg () and get () to read from a file? I can't seem to get them to work.
(DBPro has sane file inputs and outputs. Why can't c++?) Never mind. Figured it out. |
Re: OT: Stupid c++
What, exactly, is ' C:\Programming\Dev-Cpp\Projects\Simple Roguelike\Makefile.win [Build Error] [clean] Error 1 ' and why would it stop the program from compiling?
|
Re: OT: Stupid c++
>> and << are operators that are generally valid for streams (cout and cin are actually file streams). You should be able to use >> with ifstream, as per this page (ifstream is derived from istream). That site is a good reference to use. http://forum.shrapnelgames.com/images/smilies/wink.gif
I have no idea what that error means. To use a different debugger, you would have to compile with a different compiler. Microsoft's VC++ 7.1 compiler is free to get (the command line version), which you should be able to plug in to DevC++ (if it is worth it's salt). |
Re: OT: Stupid c++
|
Re: OT: Stupid c++
Fyron: I read that page, but when I tried it, it didn't seem to work. Thanks, I'll check out that compiler.
AngleWyrm: Thanks, but as I said when I edited the message, I figured it out. |
Re: OT: Stupid c++
If anyone wants to see where I am, the aptly named Simple Roguelike. Just drop it in a folder and run. Right now it's *very* simple, but as far as I know, everything works.
|
Re: OT: Stupid c++
Nice! I especially like the light radius effect, and field of view.
Found a link for the source code for NetHack v3.42; could have some interesting ways to do stuff in it. |
Re: OT: Stupid c++
Thanks. The currently linked version is my second upload; it has one type of trap. Previous savegames won't work, either.
|
Re: OT: Stupid c++
Nice job!
|
Re: OT: Stupid c++
Thanks.
Somehow, my pointer item vector is getting messed up between its setup and the function to display it. The thing is, those are the only two points which have anything to do with items at all. How is this modifying a vector?!?! Quote:
|
Re: OT: Stupid c++
Can anybody see a problem with this:
Quote:
|
Re: OT: Stupid c++
Bug: if(t2 = 0) // assign zero to t2, return true (successful assignment)
You probably meant: if(t2==0) // test for equality Happens so often that some compilers even have a warning for it. |
Re: OT: Stupid c++
Thanks. We're whacking it into shape on IRC.
|
Re: OT: Stupid c++
Update: Simple Roguelike v0.1.2.5
Features one type of weapon and one type of potion (healing). There are few glitches, but nothing game-breaking, I think. Fixed a few game-breakers. Now, to make it generate new items with a new level. |
Re: OT: Stupid c++
|
Re: OT: Stupid c++
How important is it that an object has a destructor? As far as I know, the 'delete' command is unstable.
|
Re: OT: Stupid c++
Classes should define a destructor if something needs to happen every time one gets destroyed (either by delete or by a non-static member going out of scope). It is important to prevent memory leaks if the class has any heap-allocated memory that it maintains the only pointer to and should remove when it dies.
If an object has no heap-allocated memory (i.e. it doesn't create anything with "new" or "malloc"), and if nothing needs to happen when it gets deleted, then it doesn't need a destructor. However, I really doubt any worthwhile C++ compiler is going to have a fundamental problem with destructors or with delete. If it did, it would be seriously crippled. I expect probably you are seeing some other bug. What are you deleting when you see problems? Objects with destructors that do things like use objects that are already destroyed? |
Re: OT: Stupid c++
Huh?
No, I use data types like 'int' and 'char'. Never new. I just had a vague memory of someone saying the 'delete' command was unreliable. Not using delete. I have, in fact, no destructors at all and a vague feeling that this might be bad. |
Re: OT: Stupid c++
Destructors are simply functions that get called when an object is deleted. If you never use new or malloc, then you probably never use delete nor free either, and your objects will only be deleted automatically - i.e. if they are local to a function and that function exits, or when the program exits. In other words, it sounds like you probably don't need to worry about destructors at all.
What are you going to do about creating new things during play, though, like new monsters, items, levels, etc.? Are you using STL lists of objects (not of pointers to objects) and just adding them and removing them from those? If so, then imagining how your code probably looks, STL should be doing the cleanup for you, and you shouldn't need to define destructors... ... well, ok, as long as you don't start using pointers or references to items in those lists, and expecting them to always be there after other events have happened that might have removed them from the lists. That could lead to a nice invalid pointer or reference and crash. Example: Say you have a list of all monsters in the world called MonsterList. Then say you have a Quest object to slay a particular monster, which when it gets launched, adds a monster to MonsterList and then keeps a pointer or reference to that monster object, to refer to the monster to slay. Now, if something in the game can remove the monster from MonsterList, causing its object to be automatically deleted by STL, then referring to a reference or pointer to it will be an access violation and boom. So if you want to avoid that, you could give monsters also a unique ID, and when you refer to them, always go search the list. Of course, that's a fairly slow operation, but you probably don't care too much until you have thousands of things going on at once in your gameworld. To be faster, you could have a destructor that announces when something gets deleted, and causes everything that might refer to it to drop their pointers and references to it. Sounds like you'd probably be better off keeping things simple and reliable for now, though. |
Re: OT: Stupid c++
Currently I'm using vectors for items and an array for the map.
I'm using pointers for characters, but that's the next thing I'm going to replace. In the meantime, the number of characters never changes; dead characters are simply re-randomized. Thanks. |
Re: OT: Stupid c++
Update: Simple Roguelike v0.1.4
It's been extensivly tested for all of two or three minutes, but everything should work. No cosmetic changes, but a lot of code was fixed so as to result in less heart attacks on IRC. Also, it's nearly 2MB, so I stuck it in a .rar |
Re: OT: Stupid c++
Readme's are good. I added one, just in case people hadn't found the help key.
|
Re: OT: Stupid c++
// my.h header file, using a vector
#ifndef MY_H #define MY_H #include <vector> using namespace std; class test{ public: test(){}; int insert(int in){ number_list.push_back(in); return number_list.size();}; private: vector<int> number_list; }; #endif //eof // main.cpp #include <iostream> #include "my.h" int main(){ test t; int result = t.insert(42); cout << result << endl; system("pause"); } // eof =========== Missing some white space and sequencing in the grave marker: Strength: Dexterity: 94122 Constitution: 83 Damage: 6Defence: 94.2308 HP: -1/8 XP: 0/0 Looks like stream flushing between numbers and strings. |
All times are GMT -4. The time now is 07:08 AM. |
Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©1999 - 2025, Shrapnel Games, Inc. - All Rights Reserved.