Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Variable not decreased

 
Isaac Skelton
Greenhorn
Posts: 5
C++ Java Mac
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Output section in code:

Your Life 100
There Life 100

Your Attack List
1) Punch: UNLIMITED
2) Combo Punch: 2
3) Life Drainer: 1
4) Heal Yourself: 1
5) Squash: 0
1
Your Life 100
There Life 100

Your Attack List
1) Punch: UNLIMITED
2) Combo Punch: 2
3) Life Drainer: 1
4) Heal Yourself: 1
5) Squash: 0

I have only displayed one section of this applications output because thats the bit with a problem. As you can see the life stays the same even thought I have punched which is meant to take away 5 from there life, but it isn't. How can I resolve this problem. I have supplied you with all the source code that I have done and urgently wan't a solution so please help. The line that I think is the main for this problem is...
theirLifeLineAmount = theirLifeLineAmount - 5;
 
R. Jain
Ranch Hand
Posts: 375
1
Java Python Ubuntu
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Isaac, Welcome to Code Ranch
Isaac Skelton wrote:


You see that you have declared yourLifeLineAmount and theirLifeLineAmount inside attackSection
So every time goto attackSection in invoked in that else part.. These variables are re-initialized to 100 and the earlier changed value is not reflected..

So, you have to work around with this problem..
 
R. Jain
Ranch Hand
Posts: 375
1
Java Python Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And do use a proper heading for your post..
See UseAMeaningfulSubjectLine
 
Isaac Skelton
Greenhorn
Posts: 5
C++ Java Mac
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the reply, someone else gave me the answer yesterday so the problem has now been solved. All I need to work on now are enemy attacks and some other little things.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic