• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

[C++] Help

Status
Not open for further replies.
Level 14
Joined
Jan 5, 2009
Messages
1,127
I am making an Text Based RPG using C++.

I was just checking if this is possible?

So I have a class right.

Code:
class Monster
{
      public:
             int m_damageMin, m_damageMax, m_attacks, m_health, m_defense, m_expGive;
             string m_name, m_discription, m_target;
             bool IsAlive()
             {
                  if (m_health > 0)
                  {
                               return true;
                               }
                  else
                  {
                      return false;
                      }
                      };
             bool IsAttacking()
             {
                  if (m_target == "")
                  {
                               return false;
                               }
                  else
                  {
                      return true;
                      }
                      };
                      };
ok.
So I set a mob called a wraith
Code:
Monster WraithMob()
{
        Monster Wraith;
        Wraith.m_damageMin = 8;
        Wraith.m_damageMax = 12;
        Wraith.m_attacks     = 1;
        Wraith.m_health    = 10;
        Wraith.m_defense   = 80;
        Wraith.m_expGive   = 55;
        Wraith.m_name      = "Wraith";
        Wraith.m_discription = "A Wraith is hard to hit, it only has 10 health. \nIf you manage to hit you'll most likely kill it";
        return Wraith;
}
Ok so thats like a preset type I should say.

So if I do:
Code:
Monster AttackingMonster;
AttackingMonster = WraithMob();
Will that work?

~Thanks Crazed_seal

NO STEALING MAH CODE
 
Level 22
Joined
Feb 3, 2009
Messages
3,292
That compiles fine given the proper includes etc, so you'd have to show us a copypaste of the complete file(s) that are giving you errors and what errors you are getting.

That said, when you barely know how to program you shouldn't be working in C++.

Not true at all... If he doesn't want to waste his time with learning many languages, then he should grab the best thing immediately.
 
Level 14
Joined
Jan 5, 2009
Messages
1,127
I quite like C++, depending on the coder it can have really easy readability instead of java which looks messy.

Basic Classes in C++ are easy to handle I have to say.

Although some things do actually frustrate me at times.

And C++ seems to handle things a lot better than some languages.

Add:
C++ also has alot of IDE, and Compilers compared to most languages.

And the code does work, I want this for future reference or just incase I forget...
 
Last edited:
Level 40
Joined
Dec 14, 2005
Messages
10,532
Not true at all... If he doesn't want to waste his time with learning many languages, then he should grab the best thing immediately.
First, it might very well take longer to learn C++ straight up than to learn something easier and then learn it, and you'd have another language under your belt as well.

Second, saying C++ is "the best thing" betrays a ton of ignorance.

I quite like C++, depending on the coder it can have really easy readability instead of java which looks messy.
Oh, so naive.

Basic Classes in C++ are easy to handle I have to say.
Not compared to any properly designed OO language. They look fine if you are just using basic methods and instance variables, but they are fine for that in any other language too. It's when you start doing more with them and looking at some of the syntactic behaviour that they become more messy.

And C++ seems to handle things a lot better than some languages.
Different languages have different strengths, sure. However, don't get carried away and assume that C++ doesn't have faults (and it has many).

Add:
C++ also has alot of IDE, and Compilers compared to most languages.
So? Why do you need 10 IDEs that work fine if you have 5 that work fine? And the number of compilers is a disadvantage since they don't behave identically and thus you have to tell everyone which compiler the code was developed for.

And the code does work, I want this for future reference or just incase I forget...
Yeah, assuming you add the proper includes and such the code works fine.
 
Level 9
Joined
Nov 28, 2008
Messages
704
Not true at all... If he doesn't want to waste his time with learning many languages, then he should grab the best thing immediately.

C++, best language? Maybe for graphical things requiring speed, and even then I'd direct you to C#.

C++ is hardly the best language for a text based RPG with today's ridiculously fast processors. And I'd say it's definitely not a language you should learn first. C# or Python would do better, imo.
 

Dr Super Good

Spell Reviewer
Level 63
Joined
Jan 18, 2005
Messages
27,188
C++ is hardly the best language for a text based RPG with today's ridiculously fast processors. And I'd say it's definitely not a language you should learn first. C# or Python would do better, imo.
Some of my lecturers would skin you for saying that. Faster processors is not an excuse for shitty programming practices. In the end each instruction you make a processor run costs someone money in the form of hardware life and electricity. Yes that may becomming nearly half as cheap every 18 months but that is no reason to make something more expensive to run just because you want to half assed program something.

The problem with C++ is it is a very loose specification. It works but as PurplePoot pointed out, each compiler handles code differently. The end result can be extreemly efficent OO code for a program or some buggy shit. Most comercial games use C++ (like SC2, WC3 for some popular ones) for this reason but as you can see they do have problems. Hopefully newer specifications of C++ will make the standard more strict so basic compiler features are more predectible.

C and C++ compilers allow some of the most efficent code as they can use cost models and design code with higher throughput (more instructions per unit time) than humans can with assembly due to taking into account cache usage and such. However the code is highly platform specific and some hardware performs very poorly with certain optimizations.

For a text based RPG, C++ I say may not be the best choice. Portability of it would be a major problem due to how different opperating systems handle data. You also are are respnsible for memory recycling (making sure no leaks occur).
I would peronally advise JAVA for such a task as it still has a great deal of speed (unlike python) and is nearly totally platform inspecific. This means that you get predictible behaviour weather a 64/32bit windows, mac or linux machine runs it. Its automatic garbage collector also means you do not need to worry as much about memory management.

Some web based language like javascript is also an option as that allows easy intigration into web pages and uses the browser.
 
Level 40
Joined
Dec 14, 2005
Messages
10,532
Using a programming language that emphasizes human time rather than computer efficiency when efficiency is not an issue is certainly not "shitty programming practices", though.

Java and Python are probably your best mainstream options for this. There are some interesting more obscure languages (notably Ruby and LISP) which could be pretty good too, but for most peoples' purposes Java or Python should be fine. Hell, I'd even suggest C over C++ as it's at least a bit more sane and you don't need any of the stuff that C++ adds for a text based RPG.
 
Status
Not open for further replies.
Top