CKatt wrote:I've been playing around with the code from tutorial 13 and what i am trying to do is get the meter to work for the poos instead of the goal.
I'm trying to add the meter level increase to the ProcessConsumption function so with each poo eaten the meter increases. the first problem was that i couldn't get access to the increase level function
Code: Select all
void Poo::ProcessConsumption( const Dude& dude, Meter& meter) //////////added parameter here
{
const int duderight = dude.GetX() + dude.GetWidth();
const int dudebottom = dude.GetY() + dude.GetHeight();
const int pooright = x + width;
const int poobottom = y + height;
if( duderight >= x &&
dude.GetX() <= pooright &&
dudebottom >= y &&
dude.GetY() <= poobottom )
{
isEaten = true;
meter.increaseLevel(); ////////////////////now i can call the function here
}
}
What I came up with is adding a reference to the meter in the parameters of the process consumption function. That seemed to work but now when i call the function in Game.CPP the IDE is not happy. It doesn't seem to like the added parameter. telling me 'meter is unidentified' i have included Meter.h but I guess that's not enough.
Code: Select all
poo0.ProcessConsumption( dude, meter); ////////// Visual Studio don't like me when i put meter here
maybe i'm going about this all wrong i only started with CPP a few weeks ago so there is still a lot I don't know. If anybody can explain why this doesn't work and what i could do instead I would be very grateful.
Thanks
I'll have a go at helping.
Firstly did you change the declaration of ProcessConsumption to be like the definition (with the Meter reference)?
Next I'd look at where you're calling:
Code: Select all
poo0.ProcessConsumption( dude, meter); ////////// Visual Studio don't like me when i put meter here
Do you have a variable called meter available in that scope or globally (memberly?) ?
Googling helps a lot of the time and I know C++ can give you some heinous error messages that seem to not have anything to do with the actual problem.
Keep on learning! This is about my fourth decent attempt at learning C++ throughout the last ten plus years. It gets a little easier and makes more sense as you learn.
Also I just read that you're trying to use it for the Poos instead of the Goal. I haven't looked at the code, but if Meter references Poo in any way you might have trouble building due to circular references. You would need to forward-declare one of the classes to get it to work. Forward declaration is something Chili goes into in about beginner 20 to 23 or so.