Advertisement

help missing ; before "." ??????

Started by October 12, 2002 12:58 PM
12 comments, last by vaneger 22 years, 1 month ago
take a look at my files it gives me about 40 errors with character chara; i dont know why general.h
  
#ifndef GENERAL_H_
#define GENERAL_H_
/************************************************
General section designed by AI team
other general code for other teams posted below
************************************************/
enum AiLv{PRD = 1,GAA,HAP,PAP,PEP};
/***********
AiLv determines intelligence 
level of the enemy

PRD: Psuedo-Random decisions
random number generation used for attack choices
weakest level of intelligence 
uses on/off pattern of attack

GAA: Genreal Attack Algorithms
slightly more advanced random attack algorithms
most enemys will be of this type or below
also uses on/off pattern of attack

HAP:Humanoid Attack Patterns
randomly chooses a pattern to adhere to


PAP: Pattern Attack Protocol
makes use of more sohpisticated patterns
and evaluates its state before every action

PEP: Per Enemy Programming
these are boss enemys and they are coded
individually, aka per enemy programming :)
***********/

enum State{attacking = 1};

typedef char attackName;
typedef unsigned int uint;

/************************************************
end of code section generated by AI team
other general code for other teams posted below
************************************************/

#endif
  
character.h
  
#ifndef CHARACTER_H_
#define CHARACTER_H_

#include"equipment.h"

struct character
{
	character()
	{
	}
	~character()
	{
	}
	
	//name

	char name[20];
	
	//integeral attributes

	int hitPoints;
	int magicPoints;
	int strength;
	int defense;
	int endurance;
	int speed;

	//equipment

	//list<weapon> currWeapon;

	//list<armor> currArmor;

	accessory currAccessory;

	//special attacks list

	
	//list<attackName> attacks;

	
	uint currExp;
	uint nextExp;
	int level;
};
struct enemy : public character
{
	enemy(){}
	~enemy(){}

	//non character based attributes


};


#endif
  
equipment.h
  
#ifndef EQUIPMENT_H_
#define EQUIPMENT_H_

struct armor
{
	armor()
	{
	}
	~armor()
	{
	}
	
};
struct weapon
{
};
struct accessory
{
};

typedef armor head , chest , arms , legs;
typedef weapon leftArm , rightArm , bothArms;
enum armorType{Head = 0 , Chest , Arm , Leg}armors; 
enum weaponType{Leftarm = 0, Rightarm  , Botharms}weapons;
#endif
  
combatsys.h // error is in this file
  
#ifndef COMBATSYS_H_
#define COMBATSYS_H_
#include"character.h" 

/**************
null character for debug and saftey
**************/
character chara; 
chara.name = "NULL";
chara.hitPoints = -1;
chara.magicPoints = -1;
chara.strength = -1;
chara.defense = -1;
chara.endurance = -1;
chara.speed = -1;
chara.currExp = -1;
chara.nextExp = -1;
chara.level = -1;
/**************
null character for debug and saftey
**************/

struct party
{
	party()
	{
		main = chara;
		companion = chara;
	}
	
	character main;
	character companion;

	//list<item> itemsCarried;


	void assign(const character& add, int targetPos)
	{
		if (targetPos == 1)
			main = add;
		else
			companion = add;
	}
	void remove(const character& minus)
	{
		if (companion == minus)
			companion = chara;
	}
	~party()
	{
	}
};

#endif
  
also the structs dont register in the workspace heiarchy nor do the enumerations, im really confused i know it has to be somethign little and stupid but i cant find it
Advertisement
Outside functions, you are only allowed to do initialisations ( character chara = whatever; ) not assignments ( character chara; chara.foo = whatever; ).

Documents [ GDNet | MSDN | STL | OpenGL | Formats | RTFM | Asking Smart Questions ]
C++ Stuff [ MinGW | Loki | SDL | Boost. | STLport | FLTK | ACCU Recommended Books ]
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan
EDIT: Yeah, what Fruny said





chara.name = "NULL";

Most notably, you can't do that. There is no built-in char array copier.

Also, I'm not sure if structs have a built-in operator=. That may be causing problems when assigning one character to another.

Could you tell us what line exactly the first error occurs on? Most often this error is caused by a lack of a semi-colon after a class declaration, but I can't see anything out of the ordinary.

Also, why exactly are you using structs instead of classes?

Later,
ZE.

//email me.//zealouselixir software.//msdn.//n00biez.//
miscellaneous links


[edited by - zealouselixir on October 12, 2002 2:30:38 PM]

[twitter]warrenm[/twitter]

ok got only 1 error now, chara.name="NULL";
cannot convert from char[5] to char[20] how do i fix that?
the group im coding with are all newbies so i cant use pointers or classes or alot of stuff so im working with what i can use, how should i code the struct character = operator? also how can i code a char array copier?

[edited by - vaneger on October 12, 2002 2:39:05 PM]
Advertisement
quote: Original post by ZealousElixir
chara.name = "NULL";
...
Also, I''m not sure if structs have a built-in operator=. That may be causing problems when assigning one character to another.
...
Also, why exactly are you using structs instead of classes?


vaneger: Use a C++ string instead. They''re easier, safer and more powerful. About all you lose is the ability to to a bitwise copy of your object.

ZealousElixir: They do, both in C and in C++. That''s what justifies their existance : not having to manually copy each member. Also, just to be pedantic, struct are classes

Documents [ GDNet | MSDN | STL | OpenGL | Formats | RTFM | Asking Smart Questions ]
C++ Stuff [ MinGW | Loki | SDL | Boost. | STLport | FLTK | ACCU Recommended Books ]
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan

  #include <string.h>strcpy(chara.name, "NULL");  
Chess is played by three people. Two people play the game; the third provides moral support for the pawns. The object of the game is to kill your opponent by flinging captured pieces at his head. Since the only piece that can be killed is a pawn, the two armies agree to meet in a pawn-infested area (or even a pawn shop) and kill as many pawns as possible in the crossfire. If the game goes on for an hour, one player may legally attempt to gouge out the other player's eyes with his King.
quote: Original post by vaneger
the group im coding with are all newbies so i cant use pointers or classes or alot of stuff so im working with what i can use, how should i code the struct character = operator? also how can i code a char array copier?


That's an even greater incentive to try and do things the correct way. Far too many 'newbies' stubbornly reject the use of the standerd classes (common use of the std::string class is intuitive : it does exactly what you expect it to do), and end up learning a stunted version of the language. I urge you to learn C++, not "C with classes".

Case in point, you say you can't use pointers a lot. Well, C strings involve a lot of pointers, null-terminators and such technicalities. std::string takes care of that for you. If they're not ready to deal with classes, you can gloss over it.

Now, to answer your question, the char array copier is named strcpy( destination, source );. With a std::string you don't have anything to do, there already is an assignment operator implemented and you can also directly assign a C-string to a std::string. To copy a std::string into a C char array, you do str.copy( array, array_length );.

Edit:
smart_idiot: Not at global scope, and #include <cstring> instead of <string.h>.

Documents [ GDNet | MSDN | STL | OpenGL | Formats | RTFM | Asking Smart Questions ]
C++ Stuff [ MinGW | Loki | SDL | Boost. | STLport | FLTK | ACCU Recommended Books ]


[edited by - Fruny on October 12, 2002 2:53:23 PM]
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan
thanks guys i got it working with strcpy pls close this topic now

This topic is closed to new replies.

Advertisement