Author Topic: C++ Help.  (Read 1935 times)

0 Members and 1 Guest are viewing this topic.

I need some help. I'm making a mission builder for FSO, so someone can make a mission, edit it to add vars to be randomized, and then toss it through my program to make a complete mission for use in FSO for skirmishes and the like.

This is also my first bit of C++ ever, so naturally I have no idea what the hell is going on.

I get a whole bunch of errors from the compiler (VC6) that I simply can't place, and I need someone who knows his C to help me out. I'm right now stuck at even the most basic things. (A system to check if a message has to be outputted, so I won't have to comment/uncomment messages each time I change something.)

Anyone want to help me?

http://www.sectorgame.com/FSCZ/kasperl/temp/Builder/
That is a dir with all the files from the 'project'.

EDIT:

the most recent upload, works without issues, thanks.
http://www.sectorgame.com/FSCZ/kasperl/temp/builder3.rar/
« Last Edit: August 02, 2004, 07:48:26 am by 936 »
just another newbie without any modding, FREDding or real programming experience

you haven't learned masochism until you've tried to read a Microsoft help file.  -- Goober5000
I've got 2 drug-addict syblings and one alcoholic whore. And I'm a ****ing sociopath --an0n
You cannot defeat Windows through strength alone. Only patience, a lot of good luck, and a sledgehammer will do the job. --StratComm

 

Offline jdjtcagle

  • 211
  • Already told you people too much!
Iiinteerreessstiiing...
Good luck :)
"Brings a tear of nostalgia to my eye" -Flipside
------------------------------------------
I'm an Apostolic Christian (Acts: 2:38)
------------------------------------------
Official Interplay Freespace Stories
Predator
Hammer Of Light - Omen of Darkness
Freefall in Darkness
A Thousand Years

 
Yeah, well, it won't even compile right now.
just another newbie without any modding, FREDding or real programming experience

you haven't learned masochism until you've tried to read a Microsoft help file.  -- Goober5000
I've got 2 drug-addict syblings and one alcoholic whore. And I'm a ****ing sociopath --an0n
You cannot defeat Windows through strength alone. Only patience, a lot of good luck, and a sledgehammer will do the job. --StratComm

 
Well, I've found a gazillion spelling errors and a few cases of incorrect usage of classes and often-times the () isn't placed after a function call (which also means I have no idea what's supposed to go into the braces).

Oh and use #include < iostream > instead of #include < iosteam.h >

And I'm not sure, but I don't think it's a good idea to call global functions from within a class.


Code: [Select]
int MLevel2 = MLevel1::GetMLevel();

Considering that MLevel1 is the name of your class, this isn't going to work.  You need to work with an instance of the class.

Code: [Select]
if(Level < MLevel1)

Likewise here.
« Last Edit: July 31, 2004, 03:16:21 pm by 998 »

 

Offline WMCoolmon

  • Purveyor of space crack
  • 213
In mlevel.h, getmlevel needs to return some sort of value (void or otherwise) - it returns an int in the CPP

It's also probably a good idea to put private things first, since classes are by default private; the way you have it is the reverse of the way it's coded in any other program.

Why is Mlevel numbered? It only declares a class type, not an instance, to do that you need to use
Code: [Select]
Mlevel Mlevel1;
or declare the name after the } and before the ; in the class definition.

When you're checking for a null pointer, if(pFirst == 0) should be if(pFilrst == NULL), it is considered bad practice to assume null pointers are 0; although they are on Win32 and Linux, I believe.

You can only have one linked list class instance in your entire program, though. All the items will be added to one big list because of the *pFirst pointer being static.

You should probably just use vectors, a linked list just adds complexity for speed, and speed isn't going to be a factor here since it's an external program / utility instead of an actual gameplay element.

A final word, you should probably make it possible to call the main mission-generating function from outside the program, so that it could be used as a plugin to FRED or something.

Edit: Oh yeah, don't ever name functions the same as pointers. It'll confuse the compiler because it won't be able to tell if you're talking about the variable with that name or trying to use a pointer to the function.
-C

 

Offline aldo_14

  • Gunnery Control
  • 213
This might be of use;
http://www.cplusplus.com/doc/tutorial/index.html

(I started working through this a few months ago, up till the point I actually started work and thus ran out of time - I found it pretty useful)

 

Offline jdjtcagle

  • 211
  • Already told you people too much!
I started a mission, what all does it need exactly?
It's halfway there and doesn't require mods
"Brings a tear of nostalgia to my eye" -Flipside
------------------------------------------
I'm an Apostolic Christian (Acts: 2:38)
------------------------------------------
Official Interplay Freespace Stories
Predator
Hammer Of Light - Omen of Darkness
Freefall in Darkness
A Thousand Years

 

Offline vyper

  • 210
  • The Sexy Scotsman
Working code.

Seriously, give him some time to get this perfected or you may end up having to rewrite parts of the said mission. :) Take it from one who knows, you go through several iterations of most small applications during development, all handling the problem in a slightly different/better way.
"But you live, you learn.  Unless you die.  Then you're ****ed." - aldo14

 
Thanks for all the help, I'll try to start fixing things.

And remaining some stuff.
just another newbie without any modding, FREDding or real programming experience

you haven't learned masochism until you've tried to read a Microsoft help file.  -- Goober5000
I've got 2 drug-addict syblings and one alcoholic whore. And I'm a ****ing sociopath --an0n
You cannot defeat Windows through strength alone. Only patience, a lot of good luck, and a sledgehammer will do the job. --StratComm

 
Oh yes, jdj, vyper is right. Black Wolf is right now the only one who wrote for this, and with reason. Right now, I changed the way I want the files about 3 times, and I haven't even started writing any usefull code yet. Wait untill there is at least some documentation.
just another newbie without any modding, FREDding or real programming experience

you haven't learned masochism until you've tried to read a Microsoft help file.  -- Goober5000
I've got 2 drug-addict syblings and one alcoholic whore. And I'm a ****ing sociopath --an0n
You cannot defeat Windows through strength alone. Only patience, a lot of good luck, and a sledgehammer will do the job. --StratComm

 
This is more frustrating then I thought.....

I started over, because it was such a mess more edits would only make it worse. I thought it would be better to make a Message class, and define the current level as a static int. Now, in theory, this is good, right? The constructor of a new message will output the message, so you'll only need to make a new message type variable, and make sure it get's killed. Not that hard, right?

Well, it won't even compile. Mind you, it's only one error now, instead of 44 the last time. And I've managed to keep all the stuff in one file, instead of 10. I'll upload the code in a moment, but I just can't figure out why it won't compile. It complains about the static int, this error:

main.obj : error LNK2001: unresolved external symbol "private: static int  Message::SendLevel" (?SendLevel@Message@@0HA)
Debug/Builder2.exe : fatal error LNK1120: 1 unresolved externals


edit:
www.sectorgame.com/FSCZ/kasperl/temp/Builder2/
« Last Edit: August 01, 2004, 05:01:00 am by 936 »
just another newbie without any modding, FREDding or real programming experience

you haven't learned masochism until you've tried to read a Microsoft help file.  -- Goober5000
I've got 2 drug-addict syblings and one alcoholic whore. And I'm a ****ing sociopath --an0n
You cannot defeat Windows through strength alone. Only patience, a lot of good luck, and a sledgehammer will do the job. --StratComm

 

Offline WMCoolmon

  • Purveyor of space crack
  • 213
IIRC, static has a different meaning in classes - it is the same for all instances of that class.
-C

 
That's exactly what I wanted. I want that var to be the same for all the intances. The problem is, I nearly copied the code from C++ for Dummies, only changing names and stuff, but it won't compile.
just another newbie without any modding, FREDding or real programming experience

you haven't learned masochism until you've tried to read a Microsoft help file.  -- Goober5000
I've got 2 drug-addict syblings and one alcoholic whore. And I'm a ****ing sociopath --an0n
You cannot defeat Windows through strength alone. Only patience, a lot of good luck, and a sledgehammer will do the job. --StratComm

 

Offline WMCoolmon

  • Purveyor of space crack
  • 213
Well, you never set the value for it, that could be a problem...

I think you're 'focusing on object-oriented code too much. This is much simpler, and will run faster:

Code: [Select]
//This is a global
const int OuputLevel = 50;

//Later on
void OutputMessage(char* MessageText, int Level = 90)
{
     if(Level >= OutputLevel)
          cout << MessageText;
}


Id recommend making it possible to easily output variables - this would force you to learn more about creating custom IOStreams though, or require you to use C functions for text-based output.

Also before implementing messages for constructors/destructors, at least glance through how VCs debugger runs. It takes a little learning but can be very very useful. Outputting every construction/destruction will likely just slow your program down and make it impossible to tell what happens when you output them.
« Last Edit: August 01, 2004, 05:21:47 am by 374 »
-C

  
I'd rather not start playing around with the iostreams just yet, but I'll just dump the whole object approach.
just another newbie without any modding, FREDding or real programming experience

you haven't learned masochism until you've tried to read a Microsoft help file.  -- Goober5000
I've got 2 drug-addict syblings and one alcoholic whore. And I'm a ****ing sociopath --an0n
You cannot defeat Windows through strength alone. Only patience, a lot of good luck, and a sledgehammer will do the job. --StratComm

 

Offline WMCoolmon

  • Purveyor of space crack
  • 213
add
Code: [Select]
<< endl;

onto thwe wend so wecwerything isnt writtwen to thwe samwe linwe.

Dammit, that watwer
i spil
l

wed on my kweyboard rweally did short circuit it. :p
-C

 
Thanks, I got it to compile now.

And I suggest a good soaking for the keyboard, a week drying, and then using it. I hope you've got a backup.
just another newbie without any modding, FREDding or real programming experience

you haven't learned masochism until you've tried to read a Microsoft help file.  -- Goober5000
I've got 2 drug-addict syblings and one alcoholic whore. And I'm a ****ing sociopath --an0n
You cannot defeat Windows through strength alone. Only patience, a lot of good luck, and a sledgehammer will do the job. --StratComm

 
OK, WTF?

I got the entire thing to work, without problems. I add a new CPP file, and put a new class in there, ini. I add some basic output messages to the constructor, using the message thingy we just build, and now it says "illegal pure syntax, must be '= 0' about the line where I define the OutputLevel.

I changed nothing on that line, what the hell is going on?

Edit: I updated the stuff on the FTP, www.sectorgame.com/FSCZ/kaserl/temp/builder2/
« Last Edit: August 01, 2004, 07:09:36 am by 936 »
just another newbie without any modding, FREDding or real programming experience

you haven't learned masochism until you've tried to read a Microsoft help file.  -- Goober5000
I've got 2 drug-addict syblings and one alcoholic whore. And I'm a ****ing sociopath --an0n
You cannot defeat Windows through strength alone. Only patience, a lot of good luck, and a sledgehammer will do the job. --StratComm

 
just another newbie without any modding, FREDding or real programming experience

you haven't learned masochism until you've tried to read a Microsoft help file.  -- Goober5000
I've got 2 drug-addict syblings and one alcoholic whore. And I'm a ****ing sociopath --an0n
You cannot defeat Windows through strength alone. Only patience, a lot of good luck, and a sledgehammer will do the job. --StratComm

 

Offline WMCoolmon

  • Purveyor of space crack
  • 213
Well, your class definition doesn't have a closing bracket or semicolon and there's a random semicolon right after iniparse.h is included.

(Typing on my backup, an MS Natural Keyboard)
-C