Page 1 of 1

Annaoing problem

Posted: Fri Jan 07, 2011 6:52 pm
by THe Floating Brain
I have been struggling with this problem for months (I am using C++). Some how when I go to use one of the functions inside of one of my classes instances it uses the function from the whrong instance (instances are allocated into a std::vector and have refresh functions that have all the other functions called inside it, refresh functions are called in a while loop). Somehow also varibles in one isntance's values are some how getting transfered to another instances values for that instances instance for that variable. :nono: :cry: :( :roll: For example this may be my command prompt log:
(Lest say I clicked on space ship ID# 1)
-----=====-----
ID: 5
Selection variable: true
Authorization to move variable: false
... later randomly
ID: 9
Selection variable: true
Authorization to move variable: false
--------=========------------
(now lets pretened I right clicked to move my space ship)
ID: 7
Selection variable: false
Authorization to move variable: true
--------==============--------
ID: 1
Selection variable: false
Aut1orization to move variable: true
-----------============-----------
ID: 3
Selection variable: false
Authorization to move variable: true
Moving to destination


I have no Idea as to how this is happining beacuse all my varibles have pointers they are private and every time I use one in a function I put a & before it ex. in blaaa(int &x) { //stuff// }
Can someone pleeeeease help me :worship: :worship:
If anyone needs clarification just ask I sometimes have a hard time getting my point across. :oops:

Re: Annaoing problem

Posted: Fri Jan 07, 2011 7:40 pm
by short
Show some example code

Re: Annaoing problem

Posted: Fri Jan 07, 2011 8:09 pm
by Ginto8
short wrote:Show some example code
this, because I honestly didn't understand much of what you said. You sent it out there without any context whatsoever, and context is everything.

Re: Annaoing problem

Posted: Fri Jan 07, 2011 8:38 pm
by THe Floating Brain
What kind of comments do you want I have none whatsoever XD
------------------------------------------=====EDIT=======------------------------------------------------
Il post some anyway though jast ask if you want comments

Code: Select all

	//This classes refresh function.//
	void refresh()
	{
		RTSFunctions RTSFUNC;
		cout<<"A 'fedships' 'refresh' Function Has Been Called.";
		cout<<endl;
		cout<<"The 'fgotox' Varible Inside A Instance Of 'fedship' Is Currently ";
		cout<<*fgotoxp;
		cout<<endl;
		cout<<"The 'fgotoy' Varible Inside A Instance Of 'fedship' Is Currently ";
		cout<<*fgotoyp;
		cout<<endl;
		float hs = 32;
		RTSFUNC.RTSLeftClickCheck(*selecp, FSS, FSS.GetPosition().x, FSS.GetPosition().y, 0, hs, /*App,*/ ca.getcup().getcannotp(), false, *IDP, ca.getcup().getCSIp());
		if(*selecp == true)
		{
			ca.getcup().getcannotp() = true;
		}
		cout<<"A Instance Of 'fedship''s Varible '*selecp' Is Currently "<<*selecp<<endl;
		RTSFUNC.RTSSelect(*selecp, *IDP, ca.getcup().getCSIp(), *alivefsp);
		cout<<"A Instance Of 'fedship''s Varible '*selecp' Is Currently "<<*selecp<<endl;
		cout<<"A Instances Of 'fedship''s '*rightclkp' Varible Is Currently "<<*rightclkp<<endl;
		cout<<"A Instances Of 'fedship''s '*alivefsp' Varible Is Currently "<<*alivefsp<<endl;
		cout<<"Java FAILS In Comparison To C++! Mac OS(Any Version) Fails To Windows(Of Any Version)!"<<endl;
		OnInput INPUT;
		if(*selecp == true)
		{
			INPUT.OfRightClick(ca.getcup().getCursorS().GetPosition().x, ca.getcup().getCursorS().GetPosition().y, 0, *fgotoxp, *fgotoyp, 0);
		}
		RTSFUNC.TriggerMoveToPoint(*selecp, *alivefsp, *rightclkp, *IDP, ca.getcup().getCSIp());
		RTSFUNC.RTSDestinationSetVectorCalculationAndMovement(*rightclkp, blaa, *IDP, ca.getcup().getCSIp(), *fgotoxp, *fgotoyp, *selecp, FSS, *fmovetp, *moveiskp, *alivefsp, *dirxp3, *diryp3, 0, *speedap, *calcdonep);
		if(*rightclkp == false)
		{
			ca.getcup().getcannotp() = false;
		}
		//Uuuh dont even bother with this pice of code it's fine but annioing.//
		float THEX = FSS.GetPosition().x;
		float THEY = FSS.GetPosition().y;
	/////////////////	RTSFUNC.Move(*selecp, THEX, THEY, 32, *fgotoxp, *fgotoyp, true, *fpointa, *moveiskp, *paiaxp, *fspawnedp, true, FSS, true, 2);
		if(getfpointap() != getfpointaap() && getdontdothat1() == false)
		{
			float fpointastuff();
		}
		if(*alivefsp == true && *inbattlep == true)
		{
			App.Draw(FSS);
			std::cout<<"Render Complete."<<endl;
		}
		//So this only works if there is a battle screen open.//
		cout<<"A Instance Of 'fedship's' 'x' Coordinate Is "<<FSS.GetPosition().x<<endl;
		cout<<"A Instance Of 'fedship's' 'y' Coordinate Is "<<FSS.GetPosition().y<<endl;
		cout<<"A Instance Of 'fedship's' 'rightclk' Varible Is "<<getrightclkp()<<endl;
		cout<<"A Instance Of 'fedship's' 'IDP' Varible Is Currently "<<*IDP<<endl;
		cout<<"---------------------------==========================-----------------------"<<endl;
	}
This is the begining of the class that has this function

Code: Select all

class fedship : public VeiwableB//The diffrence between VeiwableA and VeiwableB is that VeiwableB inherits From ObjectFunctions.//
This is my "object functions".

Code: Select all

class ObjectFunctions
{
public:
	class RTSFunctions
	{
	public:
		int RTSSelect(bool &SelectVar, int &ID, int &MouseIDVar, bool &alive)
		{
			if(SelectVar == true && alive == true)
			{
				if(MouseIDVar > 0)
				{
					return 0;
				}
				MouseIDVar = ID;
				if(ID == MouseIDVar)
				{
					SelectVar = true;
					int C = 0;
					int mrr = 10;
					while(mrr > C)
					{
						cout<<"BLARRRG!";
						cout<<endl;
						cout<<"Imput Recived (Left Click).";
						cout<<endl;
						C++;
					}
				}
				else
				{
					SelectVar = false;
				}
				//Oye Veh!//
			}
		}
	void RTSLeftClickCheck(bool &SelectVar, sf::Sprite &A,const float &SpriteCenterX,const float &SpriteCenterY, float SpriteCenterZ, float &SpriteHalfSize/*, sf::RenderWindow App*/, bool &Other, bool Value, int &ID1, int &ID2)
	{
		if(Other == Value && Input::m_Input->IsMouseButtonDown(sf::Mouse::Left) && App.GetInput().GetMouseX() >= A.GetPosition().x - SpriteHalfSize && Input::m_Input->IsMouseButtonDown(sf::Mouse::Left) && App.GetInput().GetMouseX() <= A.GetPosition().x + SpriteHalfSize && Input::m_Input->IsMouseButtonDown(sf::Mouse::Left) || App.GetInput().GetMouseY() >= A.GetPosition().y + SpriteHalfSize && Input::m_Input->IsMouseButtonDown(sf::Mouse::Left) && App.GetInput().GetMouseY() >= A.GetPosition().y - SpriteHalfSize)
			{
				int C = 0;
				while(C < 11)
				{
					cout<<"A Instance Of 'Veiwable' Has Been Left Cliked On.";
					cout<<endl;
					C++;
				}
				ID2 = ID1;
				SelectVar = true;
			//	return &SelectVar;
			}
	}
	void RTSDestinationSetVectorCalculationAndMovement(bool &TheTriggerTRUE, bool &TheTriggerTRUE2, int &ID, int &MouseObjectID, float &WereX, float &WereY, bool &SelectVar, sf::Sprite &A, bool &AuthMove, bool &AuthMoveTRUE2, bool &AliveTRUEInAndCondition, float &MovingX, float &MovingY, float MovingZ, int &Speed, bool &VectorCalculationCompleteVar)
		{
			bool calcdone = VectorCalculationCompleteVar;
			bool *calcdonep = &calcdone;
			if(TheTriggerTRUE == true && ID == MouseObjectID && MouseObjectID != 0)
				{
					//*fgotoyp = App.GetInput().GetMouseY();
					//*fgotoxp = App.GetInput().GetMouseX();
				//	TheTriggerTRUE = false;
					SelectVar = false;
					AuthMove = true;
					//MouseObjectID = 0;
					int C = 0;
					while(C < 10)
					{
						cout<<"A Instance Of 'Veiwable' Has Been Triggered To Move.";
						cout<<endl;
						C++;
					}
			}
			if(A.GetPosition().y != WereY || A.GetPosition().x != WereX)
			{
					if(AuthMove == true && AliveTRUEInAndCondition == true)
					{
							//VECTOR FORMULA!!!!!//
						int Java = 11;
						int C = 0;
						while(Java < C)
						{
							cout<<"'Veiwable' Calculating Vector";
							cout<<endl;
							C++;
						}
				//			getfgotoxp() += getdirxp() = FSS.GetPosition().x;
				//			getfgotoyp() += getdiryp() = FSS.GetPosition().y;
							MovingY = WereY;
							MovingX = WereX;
							WereX * MovingX;
							WereX * MovingY;
							//getdirxp3() += getdiryp3() = getptp();
							MovingY / 0;
							MovingX / 0;
							cout<<"A Instance Of 'Veiwable''s Vector Calculation Has Been Completed.";
							cout<<endl;
							//AuthMove = false;
							//AuthMove = false;
							*calcdonep = true;
							//getdiryp2() = getfgotoyp();
							//getdirxp2() = getfgotoxp();
						//	*diryp2 -= FSS.GetPosition().y;
						//	*dirxp2 -= FSS.GetPosition().x;
							MovingX -= A.GetPosition().x;
							MovingY -= A.GetPosition().y;
					}
					if(*calcdonep == true && AliveTRUEInAndCondition == true)
					{	
						int C = 0;
						while(C < 10)
						{
							cout<<"A Instance Of 'Veiwable' 'Moveing'.";
							cout<<endl;
							C++;
						}
						if(WereX >= A.GetPosition().x && A.GetPosition().x < WereX)
						{
						//	getdirxp3() -= 1;// getdirxp3();
							float a;
							//a = getfgotoxp();
							{
								float *geta = &a;
								float dis = WereX;
								dis -= A.GetPosition().x;
								if(dis >= Speed)
								{
									*geta = Speed;
								}
								else
								{
									*geta = 1;
								}
							}
							A.Move(a, 0);
					}
					if(WereY >= A.GetPosition().y && A.GetPosition().y < WereY)
					{
					//	getdiryp3() -= 1;//getdiryp3();
						float a;
						{
							float *geta = &a;
							float dis = WereY;
							dis += A.GetPosition().y;
							if(dis >= Speed)
							{
								*geta = Speed;
							}
							else
							{
								*geta = 1;
							}
						}
						//a = getfgotoyp();
						//a = *speedap;
						A.Move(0, a);
					}
					if(WereX < A.GetPosition().x && A.GetPosition().x > WereX)
					{
					//	getdirxp2() += 1;
						float a;
						{
							float *geta = &a;
							float dis = WereX;
							dis += A.GetPosition().x;
							if(dis <= Speed)
							{
								*geta = Speed;
							}
							else
							{
								*geta = 1;
							}
						}
						//a = getfgotoxp();
						//a = *speedap;
						A.Move(-a, 0);
					}
					if(WereY < A.GetPosition().y && A.GetPosition().y > WereY)
					{
						float a;
					//	a = getfgotoyp();
						{
							float *geta = &a;
							float dis = Speed;
							dis -= A.GetPosition().y;
							if(dis >= Speed)
							{
								*geta = Speed;
							}
							else
							{
								*geta = 1;
							}
						}
					//	a = *speedap;
						A.Move(0, -a);
				//		getdiryp3() += 1;
					}
					//FSS.Move(getdirxp3() , getdiryp3());
					{
						int smib = 10;
						int bib = 0;
						while(bib != smib)
						{
							cout<<"A Instance Of 'Veiwable' Moving To Destination"<<endl;
							bib += 1;
						}
					}
					if(MovingX >= 1)
					{
						MovingX -= Speed;// getdirxp3();
					}
					if(MovingY >= 1)
					{
						MovingY -= Speed;//getdiryp3();
					}
					if(MovingX < 0)
					{
						MovingX += Speed;
					}
					if(MovingY < 0)
					{
						MovingY += Speed;
					}
					if(MovingX == 0 && MovingY == 0) //&& getalivefsp() == true)
					{
						TheTriggerTRUE2 = false;
						AuthMoveTRUE2 = false;
						*calcdonep = false;
						TheTriggerTRUE = false;
						AuthMove = false;
						//Reseting varibles.//
						cout<<"A Instance Of 'Veiwable' Is Reseting Some Varibles.";
						cout<<endl;
						MouseObjectID = 0;
						//return MouseObjectID;
					}
					}
				}
			}
			void TriggerMoveToPoint(bool &SelectVarTRUE, bool &AliveTRUE, bool &TriggerTRUE, int &ID, int &MouseID)
			{
				if(Input::m_Input->IsMouseButtonDown(sf::Mouse::Right) && SelectVarTRUE == true && AliveTRUE == true && ID == MouseID)
				{
					int C = 0;
					while(C < 10)
					{
						cout<<"Imput Recived (Right Click)";
						cout<<endl;
						C++;
					}
					TriggerTRUE = true;
					//return TriggerTRUE;
				}
			}
			void Rotate(float &WereX, float &WereY, float &Pointa, bool &OkeyToMove, bool &AtX, bool &WhileVarTrue, bool WhileVarTrueValue,sf::Sprite &A, bool OkeyToMoveValue)
			{
				if(WhileVarTrue == WhileVarTrueValue)
				{
					if(WereX > Pointa && AtX == false)
					{
						Pointa += 1;
					}
					if(WereX < Pointa && AtX == false)
					{
						Pointa -= 1;
					}
					if(Pointa == WereX && AtX == false)
					{
						AtX == true;
					}
					if(AtX == true)
					{
						if(WereY > Pointa)
						{
							A.Rotate(-1);
						}
						if(WereY < Pointa)
						{
							A.Rotate(1);
						}
						if(Pointa == WereY)
						{
							bool b = WhileVarTrue;
							if(b == true)
							{
								WhileVarTrue = false;
							}
							if(b == false)
							{
								WhileVarTrue = true;
							}
							OkeyToMove = OkeyToMoveValue;
						}
					}
				}
			}
			
	void Move(bool &GotoOrSelect, float &CenterX, float &CenterY, float SpriteHalfSize, float &WereX, float &WereY, bool GotoOrSelectValue,float &Pointa, bool &OkeyToMove, bool &AtX, bool &WhileVarTrue, bool WhileVarTrueValue,sf::Sprite &A, bool OkeyToMoveValue, int Speed)
		{
			if(WhileVarTrue == WhileVarTrueValue)
				{
					if(WereX > Pointa && AtX == false)
					{
						Pointa += 1;
					}
					if(WereX < Pointa && AtX == false)
					{
						Pointa -= 1;
					}
					if(Pointa == WereX && AtX == false)
					{
						AtX == true;
					}
					if(AtX == true)
					{
						if(WereY > Pointa)
						{
							A.Rotate(-1);
						}
						if(WereY < Pointa)
						{
							A.Rotate(1);
						}
						if(Pointa == WereY)
						{
							bool b = WhileVarTrue;
							if(b == true)
							{
								WhileVarTrue = false;
							}
							if(b == false)
							{
								WhileVarTrue = true;
							}
							OkeyToMove = OkeyToMoveValue;
						}
					}
				}
				if(OkeyToMove == OkeyToMoveValue && GotoOrSelect == GotoOrSelectValue)
				{
					if(CenterX > WereX)
					{
						CenterX -= Speed;
					}
					if(CenterX < WereX)
					{
						CenterX += Speed;
					}
					if(CenterY > WereY)
					{
						CenterY += Speed;
					}
					if(CenterX < WereX)
					{
						CenterY -= Speed;
					}
					if(CenterX == WereX && CenterY == WereY)
					{
						bool a, b;
						a = OkeyToMoveValue;
						if(a == true)
						{
							a = false;
						}
						if(a == false)
						{
							a = true;
						}
						b = GotoOrSelectValue;
						if(b == true)
						{
							b = false;
						}
						if(b == false)
						{
							b = true;
						}
					}
				}
				if(GotoOrSelect != GotoOrSelectValue)
				{
					if(Input::m_Input->IsMouseButtonDown(sf::Mouse::Left) && App.GetInput().GetMouseX() >= A.GetPosition().x - SpriteHalfSize && Input::m_Input->IsMouseButtonDown(sf::Mouse::Left) && App.GetInput().GetMouseX() <= A.GetPosition().x + SpriteHalfSize || Input::m_Input->IsMouseButtonDown(sf::Mouse::Left) && App.GetInput().GetMouseY() >= A.GetPosition().y - SpriteHalfSize && Input::m_Input->IsMouseButtonDown(sf::Mouse::Left) && App.GetInput().GetMouseY() >= A.GetPosition().y + SpriteHalfSize) //I think this may be my problem right here Iim playing around wiht it.//
					{
						GotoOrSelect == GotoOrSelectValue;
					}
				}
			}
	};
	class OverHeadShooterFucntions
	{
	public:
	};
	class OnInput
	{
	public:
		void OfRightClick(float SetX, float SetY, float SetZ, float &x, float &y, float z)
		{
			x = SetX;
			y = SetY;
			z = SetZ;
		}
	};
};

Re: Annaoing problem

Posted: Fri Jan 07, 2011 9:56 pm
by Ginto8
I'm not going to comment on the code, because A) I don't like reading large blocks of code for no reason and B) a cursory glance shows that you need to learn about namespaces, need to get a real and proper understanding of classes and need to learn the proper use of references as well. Quite honestly, I don't want to explain any of these in a textual forum post.

But we come to the core of the problem, we don't know what the problem is. All you've given us is some console logs with some minor commenting on who-knows-what, and you act as though we should understand what each part means and what is going wrong. Do not presume. My #1 rule when it comes to asking for help on the internet (or giving it) is to make sure that you have enough context to understand the problem. Everyone has different debug output and program flow, so just posting the debug log is probably the least helpful thing possible. Pointing out what parts are unexpected or unwanted would allow us to understand what you need help with much more.

Re: Annaoing problem

Posted: Fri Jan 07, 2011 11:21 pm
by THe Floating Brain
Basicly values from when I use my varibles in my functions in a instance of a class that I have are getting transfered to other instances of that class and I dont know why. Sorry I know I have a realy hard time getting my point across.

Re: Annaoing problem

Posted: Sat Jan 08, 2011 10:15 am
by dandymcgee
Yeah you might want to read up on what passing by reference actually does.

Re: Annaoing problem

Posted: Fri Jan 21, 2011 2:42 pm
by adikid89
You should sell your code to people writing c++ books... they always need bad coding examples... :roll:

Re: Annaoing problem

Posted: Fri Jan 21, 2011 7:41 pm
by xiphirx
Oh dear god kid...

How do you even work with your code? Seriously? You're defining ALL functions inside of the class body? Ever heard of header files?

Re: Annaoing problem

Posted: Fri Jan 21, 2011 8:28 pm
by ibly31
Guys, guys guys...

Give him a break! We weren't all born with great coding habits! I can imagine getting frustrated if he was asking stupid questions and had a problem easily solved by google... but this is something complex that needs explaining BECAUSE of the nature of the problem. Although he will need to learn this at some point, why do we have to teach him like this with impatient replies?

Re: Annaoing problem

Posted: Fri Jan 21, 2011 11:24 pm
by xiphirx
ibly31 wrote:Guys, guys guys...

Give him a break! We weren't all born with great coding habits! I can imagine getting frustrated if he was asking stupid questions and had a problem easily solved by google... but this is something complex that needs explaining BECAUSE of the nature of the problem. Although he will need to learn this at some point, why do we have to teach him like this with impatient replies?
I personally spoke with him on IRC.

To me, it seems as if he doesn't know the basics of C++, which is something I (and others) advised him to review.