Annaoing problem
Moderator: Coders of Rage
- THe Floating Brain
- Chaos Rift Junior
- Posts: 284
- Joined: Tue Dec 28, 2010 7:22 pm
- Current Project: RTS possible Third Person shooter engine.
- Favorite Gaming Platforms: PC, Wii, Xbox 360, GAME CUBE!!!!!!!!!!!!!!!!!!!!!!
- Programming Language of Choice: C/C++, Python 3, C#
- Location: U.S
Annaoing problem
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. 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
If anyone needs clarification just ask I sometimes have a hard time getting my point across.
(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
If anyone needs clarification just ask I sometimes have a hard time getting my point across.
"Why did we say we were going to say we were going to change the world tomorrow yesterday? Maybe you can." - Myself
- short
- ES Beta Backer
- Posts: 548
- Joined: Thu Apr 30, 2009 2:22 am
- Current Project: c++, c
- Favorite Gaming Platforms: SNES, PS2, SNES, SNES, PC NES
- Programming Language of Choice: c, c++
- Location: Oregon, US
Re: Annaoing problem
Show some example code
My github repository contains the project I am currently working on,
link: https://github.com/bjadamson
link: https://github.com/bjadamson
- Ginto8
- ES Beta Backer
- Posts: 1064
- Joined: Tue Jan 06, 2009 4:12 pm
- Programming Language of Choice: C/C++, Java
Re: Annaoing problem
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.short wrote:Show some example code
Quit procrastinating and make something awesome.
Ducky wrote:Give a man some wood, he'll be warm for the night. Put him on fire and he'll be warm for the rest of his life.
- THe Floating Brain
- Chaos Rift Junior
- Posts: 284
- Joined: Tue Dec 28, 2010 7:22 pm
- Current Project: RTS possible Third Person shooter engine.
- Favorite Gaming Platforms: PC, Wii, Xbox 360, GAME CUBE!!!!!!!!!!!!!!!!!!!!!!
- Programming Language of Choice: C/C++, Python 3, C#
- Location: U.S
Re: Annaoing problem
What kind of comments do you want I have none whatsoever XD
------------------------------------------=====EDIT=======------------------------------------------------
Il post some anyway though jast ask if you want comments
This is the begining of the class that has this function
This is my "object functions".
------------------------------------------=====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;
}
Code: Select all
class fedship : public VeiwableB//The diffrence between VeiwableA and VeiwableB is that VeiwableB inherits From ObjectFunctions.//
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;
}
};
};
"Why did we say we were going to say we were going to change the world tomorrow yesterday? Maybe you can." - Myself
- Ginto8
- ES Beta Backer
- Posts: 1064
- Joined: Tue Jan 06, 2009 4:12 pm
- Programming Language of Choice: C/C++, Java
Re: Annaoing problem
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.
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.
Quit procrastinating and make something awesome.
Ducky wrote:Give a man some wood, he'll be warm for the night. Put him on fire and he'll be warm for the rest of his life.
- THe Floating Brain
- Chaos Rift Junior
- Posts: 284
- Joined: Tue Dec 28, 2010 7:22 pm
- Current Project: RTS possible Third Person shooter engine.
- Favorite Gaming Platforms: PC, Wii, Xbox 360, GAME CUBE!!!!!!!!!!!!!!!!!!!!!!
- Programming Language of Choice: C/C++, Python 3, C#
- Location: U.S
Re: Annaoing problem
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.
"Why did we say we were going to say we were going to change the world tomorrow yesterday? Maybe you can." - Myself
- dandymcgee
- ES Beta Backer
- Posts: 4709
- Joined: Tue Apr 29, 2008 3:24 pm
- Current Project: https://github.com/dbechrd/RicoTech
- Favorite Gaming Platforms: NES, Sega Genesis, PS2, PC
- Programming Language of Choice: C
- Location: San Francisco
- Contact:
Re: Annaoing problem
Yeah you might want to read up on what passing by reference actually does.
Falco Girgis wrote:It is imperative that I can broadcast my narcissistic commit strings to the Twitter! Tweet Tweet, bitches!
- adikid89
- Chaos Rift Cool Newbie
- Posts: 94
- Joined: Tue Apr 27, 2010 6:59 am
- Current Project: small tiny-mini projects
- Favorite Gaming Platforms: PC I guess...
- Programming Language of Choice: c++
Re: Annaoing problem
You should sell your code to people writing c++ books... they always need bad coding examples...
My first game C++/SDL Yoshi Combat! = http://www.youtube.com/watch?v=HQ9mMBEWSZg
==============================================================
==============================================================
- xiphirx
- Chaos Rift Junior
- Posts: 324
- Joined: Mon Mar 22, 2010 3:15 pm
- Current Project: ******** (Unkown for the time being)
- Favorite Gaming Platforms: PC
- Programming Language of Choice: C++
- Contact:
Re: Annaoing problem
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?
How do you even work with your code? Seriously? You're defining ALL functions inside of the class body? Ever heard of header files?
StarCraft II Zerg Strategy, open to all levels of players!
Looking for paid work :< Contact me if you are interested in creating a website, need a web design, or anything else you think I'm capable of
Looking for paid work :< Contact me if you are interested in creating a website, need a web design, or anything else you think I'm capable of
- ibly31
- Chaos Rift Junior
- Posts: 312
- Joined: Thu Feb 19, 2009 8:47 pm
- Current Project: Like... seven different ones
- Favorite Gaming Platforms: Xbox 360, Gamecube
- Programming Language of Choice: C++, ObjC
- Location: New Jersey.
Re: Annaoing problem
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?
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?
Website/Tumblr
My Projects
The best thing about UDP jokes is that I don’t care if you get them or not.
- xiphirx
- Chaos Rift Junior
- Posts: 324
- Joined: Mon Mar 22, 2010 3:15 pm
- Current Project: ******** (Unkown for the time being)
- Favorite Gaming Platforms: PC
- Programming Language of Choice: C++
- Contact:
Re: Annaoing problem
I personally spoke with him on IRC.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?
To me, it seems as if he doesn't know the basics of C++, which is something I (and others) advised him to review.
StarCraft II Zerg Strategy, open to all levels of players!
Looking for paid work :< Contact me if you are interested in creating a website, need a web design, or anything else you think I'm capable of
Looking for paid work :< Contact me if you are interested in creating a website, need a web design, or anything else you think I'm capable of