Ok guys I am extremely new to c++ and programming in General (I started trying to learn c++ a month ago and started a book called "Learning c++ by creating Games with UE4".
Now this is a hobby and so I don't get lots of time to study/learn but I decided to try the code I have learned so far and create something totally on a slight tangent from the book.
I know my code won't be prefect in its presentation and any helpful advice would be appreciated. The main problem I am having though is on lines 45 to 47 in the while loop in the main function.
It tells me that the variables PlayerOne.Health, PlayerOne.Dmg, MonsterA.Health and MonsterA.Dmg are not declared in this scope.
Now I presume this is because they are private variables within their own functions but I am struggling to find a way to make them public. Sure if I didn't have screaming kids shouting at me tonight I could probably find the answer out eventually but thought I would ask the good folks on this forum for some advice.
With Thanks
You can't use PlayerOne in the main function because you created PlayerOne in the function PlayerA, so main does not know about it. What you could do is create it in main, and send it as a function parameter to PlayerA.
Well, PlayerOne is declared inside the function PlayerA. It isn't avisible outside of that function. MonsterA is also not visible outside of CreatingMonster. Those variables are local to those two functions. I see you've learned about classes. Because those variables are local, that also means that any changes you make to them while inside those functions will be lost when the function returns.
Why not create aPlayer and Monster in main and then use a function to assign the correct values to the variables inside PlayerOne and MonsterA? You could also create a function inside each of those classes that you call, like 'PlayerOne.GetInfo()" and "MonsterA.Create()", or whatever you decided to call them.