Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  
Pages: 1 ... 167 168 [169] 170 171 ... 796

Author Topic: if self.isCoder(): post() #Programming Thread  (Read 888171 times)

alway

  • Bay Watcher
  • 🏳️‍⚧️
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #2520 on: June 17, 2012, 12:24:58 am »

Is there any reason a class can't be
Code: [Select]
extern in C++?
This linkage error is driving me slightly crazy D:
Not quite sure I understand what you mean by that; post some code and label whether each part is in a .h or .cpp
Logged

kaijyuu

  • Bay Watcher
  • Hrm...
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #2521 on: June 17, 2012, 12:27:25 am »

@Glyph

Assembly.



No really, unless you're aiming to learn a new language, stick with what you're comfortable with. There's no reason to make it harder for yourself than it has to be. If you ARE wanting to learn a new language, such a project would be great for it, but otherwise there are enough half-finished projects out there due to the programmer getting bored and/or frustrated.
Logged
Quote from: Chesterton
For, in order that men should resist injustice, something more is necessary than that they should think injustice unpleasant. They must think injustice absurd; above all, they must think it startling. They must retain the violence of a virgin astonishment. When the pessimist looks at any infamy, it is to him, after all, only a repetition of the infamy of existence. But the optimist sees injustice as something discordant and unexpected, and it stings him into action.

GlyphGryph

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #2522 on: June 17, 2012, 12:36:41 am »

See, the problem is I'm not even sure if I could say I know C++ anymore. I've been using Ruby for 2 years, and Java for the 2 before that, and back when I was programming in C++ I was a terribad programmer. Programming a roguelike in Ruby would just be silly, and that's the only one I'd be comfortable saying I know right now.

In essence, any language I program it in at this point will be a new language. So why not go for whatever.
Logged

Siquo

  • Bay Watcher
  • Procedurally generated
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #2523 on: June 17, 2012, 05:06:09 am »

See, the problem is I'm not even sure if I could say I know C++ anymore. I've been using Ruby for 2 years, and Java for the 2 before that, and back when I was programming in C++ I was a terribad programmer. Programming a roguelike in Ruby would just be silly, and that's the only one I'd be comfortable saying I know right now.

In essence, any language I program it in at this point will be a new language. So why not go for whatever.
Javascript? Make it js+HTML5 and you can roguelike on your mobile.

C++ Problem:
I have a class world with a member NMaterialManager. That class has a map of MaterialTypes. Initialising is ok, but later when I try to retrieve the materialtype, it goes wrong.
Code: [Select]
class has member:
std::map<std::string, NMaterialType*> materialTypes;

NMaterialManager::NMaterialManager(){
  // add all "normal" materials
  std::cout<<"NAM: Base size1 "<<materialTypes.size()<<"? \n";

  materialTypes["Rock"] = new NMaterialType("Rock", 20, 20, 5, 20, 0, 3000, 30000);
  std::cout<<"NAM: Base size2 "<<materialTypes.size()<<"? \n";
}

NBaseMaterial* NMaterialManager::getBaseMaterial(std::string type, double seed){
  std::string id = type+stringify(seed);
  std::cout<<"NAM: getBaseMaterial "<<id<<" \n";
  std::cout<<"NAM: Base size3 "<<materialTypes.size()<<"? \n";
}

And my output is
Code: [Select]
NAM: Start
NWOrld: set matman
NAM: Base size1 0?
NAM: Base size2 1?
NAM: World setcam
NAM: new Terrain lvl 0 id Terrain0
NAM: new Terrain set material
NAM: getBaseMaterial Rock1
NAM: Base size3 2205664762?


Dafuq? How does my map size suddenly increase from 1 to 2205664762?!
Logged

This one thread is mine. MIIIIINE!!! And it will remain a happy, friendly, encouraging place, whether you lot like it or not. 
will rena,eme sique to sique sxds-- siquo if sucessufil
(cant spel siqou a. every speling looks wroing (hate this))

Skyrunner

  • Bay Watcher
  • ?!?!
    • View Profile
    • Portfolio
Re: if self.isCoder(): post() #Programming Thread
« Reply #2524 on: June 17, 2012, 08:34:24 am »

Is there any reason a class can't be
Code: [Select]
extern in C++?
This linkage error is driving me slightly crazy D:
Not quite sure I understand what you mean by that; post some code and label whether each part is in a .h or .cpp
I mean, "what is the proper way to extern a class or a pointer to a class across multiple source files?" Pretty sure that's the problem.

Anyways, I have no access to my computer for a week, so it doesn't matter right now.
Logged

bay12 lower boards IRC:irc.darkmyst.org @ #bay12lb
"Oh, they never lie. They dissemble, evade, prevaricate, confoud, confuse, distract, obscure, subtly misrepresent and willfully misunderstand with what often appears to be a positively gleeful relish ... but they never lie" -- Look To Windward

Mego

  • Bay Watcher
  • [PREFSTRING:MADNESS]
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #2525 on: June 17, 2012, 08:41:35 am »

Siquo, is there any other code that modifies or calls any member function of materialTypes? If so, could you post it?

GlyphGryph

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #2526 on: June 17, 2012, 09:16:03 am »

Javascript? Make it js+HTML5 and you can roguelike on your mobile.

...you know what? Why not. Sure, it's not the most efficient language, but it's certainly pretty simple and the visual stuff will be fairly easy. Easy to distribute an online version OR an executable - would even be trivial to throw in user auth on the access website so people can come back and play their own accounts and whatnot (though obviously this wouldn't apply for the local versions).

I like it.

This is why I ask stuff like this here. :P
Logged

alway

  • Bay Watcher
  • 🏳️‍⚧️
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #2527 on: June 17, 2012, 09:17:13 am »

Is there any reason a class can't be
Code: [Select]
extern in C++?
This linkage error is driving me slightly crazy D:
Not quite sure I understand what you mean by that; post some code and label whether each part is in a .h or .cpp
I mean, "what is the proper way to extern a class or a pointer to a class across multiple source files?" Pretty sure that's the problem.

Anyways, I have no access to my computer for a week, so it doesn't matter right now.
Assuming you mean an instance of a class, rather than a class itself (again, I'm not quite sure which you mean), here's how you do it:

In the .h file:
Code: [Select]
class Classname;                      //declare the class, as it does not exist in this scope
extern Classname variableName;   //declare the variable with the class
In a .cpp file:
Code: [Select]
Classname variableName = Classname(); //initialize the variableAs a handy side-note, you can declare classes without defining them until later with the 'class Classname;' declaration. This allows you to do things in .h files which would otherwise result in circular linking. So long as they are defined before they are actually used (via includes in the .cpp usually), everything works fine. So you can do things like
Code: (First .h) [Select]
class Class2;
class Class1
{
   Class2* var;
};
Code: (Second .h) [Select]
class Class1;
class Class2
{
   Class1* var;
}
So long as the correct .h files are included in the .cpp files which actually use those variables, the class declarations are defined and work just as you would expect. As a general rule, you can keep a lot of #include statements out of your .h files using class declarations rather than #include. Which I'm pretty sure results in less code to recompile when you change something in code (though I'm not certain on that, and it probably varies from one IDE to the next).
« Last Edit: June 17, 2012, 09:42:49 am by alway »
Logged

Siquo

  • Bay Watcher
  • Procedurally generated
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #2528 on: June 17, 2012, 09:31:42 am »

Siquo, is there any other code that modifies or calls any member function of materialTypes? If so, could you post it?
Searching for that membername yields:
Code: [Select]
NTerrain.cpp|18|material = new NMaterial(getWorld()->matManager->getBaseMaterial("Rock", 1), NMaterial::SOLID, NMaterial::ROUGH);|
NTerrain.cpp|131|return getWorld()->matManager->getOgreMaterial(material);|
NWorld.cpp|36|matManager = new NMaterialManager();|
NWorld.h|21|NMaterialManager* matManager;|
Which are, from bottom to top, the member declaration, the initialisation (contructor), a getter, and the getter that suddenly encounters a membermap with size zillion.
There are no setters, and the only thing modifying that map is adding the one default "Rock" type material. The rest of the class is merely a cache with a factory.

*more debugging*
Hmmm, I have an ugly singleton-like member+getter like this:
Code: [Select]
class World {
  static World* world;
  static World* getSingleton(){ return world; }

  World(){ world = this; } // <- set static member in constructor
}
and when I get the world through this method it goes wrong, somehow. Whyyyy?!?!
Logged

This one thread is mine. MIIIIINE!!! And it will remain a happy, friendly, encouraging place, whether you lot like it or not. 
will rena,eme sique to sique sxds-- siquo if sucessufil
(cant spel siqou a. every speling looks wroing (hate this))

alway

  • Bay Watcher
  • 🏳️‍⚧️
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #2529 on: June 17, 2012, 09:51:56 am »

and when I get the world through this method it goes wrong, somehow. Whyyyy?!?!
Try putting a trace or breakpoint in that constructor; it may not be getting run for whatever reason.

If it isn't that, put in a destructor and see if that is run; if your original 'world' goes out of scope or something to that tune, you will have a pointer to deallocated memory.

It also sets it to the most recently created 'world;' it may be you are setting up everything in the first 'world,' then initialize a second which then causes everything to point at it, effectively nullifying any changes you made with the first since there is no [if world == null] to check if one exists, or at least none is shown there. If none of those is the case, dunno.
« Last Edit: June 17, 2012, 09:58:24 am by alway »
Logged

Siquo

  • Bay Watcher
  • Procedurally generated
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #2530 on: June 17, 2012, 10:48:43 am »

and when I get the world through this method it goes wrong, somehow. Whyyyy?!?!
If it isn't that, put in a destructor and see if that is run; if your original 'world' goes out of scope or something to that tune, you will have a pointer to deallocated memory.
This, it get destructed 7 times and constructed only once.   ??? Hmmz. More research!
Logged

This one thread is mine. MIIIIINE!!! And it will remain a happy, friendly, encouraging place, whether you lot like it or not. 
will rena,eme sique to sique sxds-- siquo if sucessufil
(cant spel siqou a. every speling looks wroing (hate this))

Virex

  • Bay Watcher
  • Subjects interest attracted. Annalyses pending...
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #2531 on: June 17, 2012, 05:44:52 pm »

See, the problem is I'm not even sure if I could say I know C++ anymore. I've been using Ruby for 2 years, and Java for the 2 before that, and back when I was programming in C++ I was a terribad programmer. Programming a roguelike in Ruby would just be silly, and that's the only one I'd be comfortable saying I know right now.

In essence, any language I program it in at this point will be a new language. So why not go for whatever.
What's so silly about programming a roguelike in Ruby?
Logged

Nadaka

  • Bay Watcher
    • View Profile
    • http://www.nadaka.us
Re: if self.isCoder(): post() #Programming Thread
« Reply #2532 on: June 17, 2012, 06:33:56 pm »

See, the problem is I'm not even sure if I could say I know C++ anymore. I've been using Ruby for 2 years, and Java for the 2 before that, and back when I was programming in C++ I was a terribad programmer. Programming a roguelike in Ruby would just be silly, and that's the only one I'd be comfortable saying I know right now.

In essence, any language I program it in at this point will be a new language. So why not go for whatever.
What's so silly about programming a roguelike in Ruby?

The same thing that is silly about programming ANYTHING in Ruby... ;)

On a different note: I have come to be bogged down implementing the UI for my diablo 3 utility and I am growing bored because this code isn't as interesting as the internals, and I could just be playing diablo 3 instead.
Logged
Take me out to the black, tell them I ain't comin' back...
I don't care cause I'm still free, you can't take the sky from me...

I turned myself into a monster, to fight against the monsters of the world.

kaijyuu

  • Bay Watcher
  • Hrm...
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #2533 on: June 17, 2012, 06:37:59 pm »

UI is the worst thing in any project. Ugh. Especially GUIs; those can burn in hell.
Logged
Quote from: Chesterton
For, in order that men should resist injustice, something more is necessary than that they should think injustice unpleasant. They must think injustice absurd; above all, they must think it startling. They must retain the violence of a virgin astonishment. When the pessimist looks at any infamy, it is to him, after all, only a repetition of the infamy of existence. But the optimist sees injustice as something discordant and unexpected, and it stings him into action.

Virex

  • Bay Watcher
  • Subjects interest attracted. Annalyses pending...
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #2534 on: June 17, 2012, 06:50:54 pm »

Thank Ogd for GUI builders :P
Logged
Pages: 1 ... 167 168 [169] 170 171 ... 796