Travis wrote:
For instance, it looks like you have two sets of code each for “player attacks” and “enemy attacks” where the code is very similar except for a couple of differences. You could consolidate each into a single subprogram and just use a variable to account for the differences (in damage calculated and locations in the list to store, if I'm reading it correctly). That would save space and potentially make the program easier to understand. And as Jeffitus said, on all the places where you have If:Then:…:End with only one instruction to execute, you can simply remove the Then and End.
Awesome! Thanks for the help and tips
EDIT: Here's where I am:
I've optimized the code like this:
Main Program:
Code: :{20,10,10,15,2,2}üENEMDAT1
:{20,10,10,15,2,2}üENEMDAT2
:{20,10,10,15,2,2}üENEMDAT3
:{25,5,5,10,0,0}üENEMDAT4
:{30,5,5,10,0,0}üENEMDAT5
:ClLCD
:Disp "CHAPTER 1"
:Disp "As you walk down the"
:Disp "hallway you spot a"
:Disp "grouping of hostile"
:Disp "looking monsters."
:Disp "Press ENTER"
:Pause
:For(R,1,5)
:1+int(5rand)üD
:If D == 1
:Then
:ENEMDAT1üENEMYDAT
:If D == 2
:Then
:ENEMDAT2üENEMYDAT
:If D == 3
:Then
:ENEMDAT3üENEMYDAT
:If D == 4
:Then
:ENEMDAT4üENEMYDAT
:If D == 5
:Then
:ENEMDAT5üENEMYDAT
:While SAVEDATA(3)>0 and ENEMYDAT(3)>0
:ClLCD
:Disp "CHAPTER 1"
:Outpt(3,1,"ENEMY:")
:Outpt(3,7,ENEMYDAT(3))
:Outpt(4,1,"YOU:")
:Outpt(4,5,SAVEDATA(3))
:Outpt(5,1,"AC:")
:Outpt(5,4,ARMDATA(1))
:Outpt(6,1,"Melee:")
:Outpt(6,7,ARMDATA(3))
:Outpt(7,1,"Ranged:")
:Outpt(7,8,ARMDATA(5))
:If SAVEDATA(1) ù ENEMYDAT(1)
:Then
:Menu(1,"Melee",MELA,2,"Ranged",RANA)
:Lbl MELA
:ARMDATA(3)üARMTEMP
:PLAYERTN
:ENEMYTN
:Lbl RANA
:ARMDATA(5)üARMTEMP
:PLAYERTN
:ENEMYTN
:Else
:Menu(1,"Melee",MELB,2,"Ranged",RANB)
:Lbl MELB
:ARMDATA(3)üARMTEMP
:ENEMYTN
:PLAYERTN
:Lbl RANB
:ARMDATA(5)üARMTEMP
:ENEMYTN
:PLAYERTN
:End
:End
:End
:If SAVEDATA(3) ÷ 0
:DEATH
:Return
Player Attack:
Code: :Disp "You attack!"
:If ENEMYDAT(4) < (int(20rand)+ARMDATA(2))
:Then
:ENEMYDAT(3)-(int(10rand)+ARMTEMP)üENEMYDAT(3)
:Disp "You hit!"
:Else
:Disp "You miss!"
:End
:Return
Enemy Attack:
Code: :Disp "Enemy attacks!"
:If ARMDATA(1) < (int(20rand)+ENEMYDAT(5))
:Then
:SAVEDATA(3)-(int(6rand)+ENEMYDAT(6))üSAVEDATA(3)
:Disp "Enemy hits!"
:Else
:Disp "Enemy misses!"
:End
:Return
These are all separate programs.
Before putting that on my calc, I decided to try this just to make sure the "End" statement would solve my issues. Here is the code in that program:
Code: :{20,10,10,15,2,2}üENEMDAT1
:{20,10,10,15,2,2}üENEMDAT2
:{20,10,10,15,2,2}üENEMDAT3
:{25,5,5,10,0,0}üENEMDAT4
:{30,5,5,10,0,0}üENEMDAT5
:ClLCD
:Disp "CHAPTER 1"
:Disp "As you walk down the"
:Disp "hallway you spot a"
:Disp "grouping of hostile"
:Disp "looking monsters."
:Disp "Press ENTER"
:Pause
:For(R,1,5)
:1+int(5rand)üD
:If D == 1
:Then
:ENEMDAT1üENEMYDAT
:If D == 2
:Then
:ENEMDAT2üENEMYDAT
:If D == 3
:Then
:ENEMDAT3üENEMYDAT
:If D == 4
:Then
:ENEMDAT4üENEMYDAT
:If D == 5
:Then
:ENEMDAT5üENEMYDAT
:While SAVEDATA(3)>0 and ENEMYDAT(3)>0
:ClLCD
:Disp "CHAPTER 1"
:Outpt(3,1,"ENEMY:")
:Outpt(3,7,ENEMYDAT(3))
:Outpt(4,1,"YOU:")
:Outpt(4,5,SAVEDATA(3))
:Outpt(5,1,"AC:")
:Outpt(5,4,ARMDATA(1))
:Outpt(6,1,"Melee:")
:Outpt(6,7,ARMDATA(3))
:Outpt(7,1,"Ranged:")
:Outpt(7,8,ARMDATA(5))
:If SAVEDATA(1) ù ENEMYDAT(1)
:Then
:Menu(1,"Melee",MELA,2,"Ranged",RANA)
:Lbl MELA
:Disp "You attack!"
:If ENEMYDAT(4) < (int(20rand)+ARMDATA(2))
:Then
:ENEMYDAT(3)-(int(10rand)+ARMDATA(3))üENEMYDAT(3)
:Disp "You hit!"
:Else
:Disp "You miss!"
:End
:Disp "Enemy attacks!"
:If ARMDATA(1) < (int(20rand)+ENEMYDAT(5))
:Then
:SAVEDATA(3)-(int(6rand)+ENEMYDAT(6))üSAVEDATA(3)
:Disp "Enemy hits!"
:Else
:Disp "Enemy misses!"
:End
:Lbl RANA
:Disp "You attack!"
:If ENEMYDAT(4) < (int(20rand)+ARMDATA(4))
:Then
:ENEMYDAT(3)-(int(8rand)+ARMDATA(5))üENEMYDAT(3)
:Disp "You hit!"
:Else
:Disp "You miss!"
:End
:Disp "Enemy attacks!"
:If ARMDATA(1) < (int(20rand)+ENEMYDAT(5))
:Then
:SAVEDATA(3)-(int(6rand)+ENEMYDAT(6))üSAVEDATA(3)
:Disp "Enemy hits!"
:Else
:Disp "Enemy misses!"
:End
:Else
:Menu(1,"Melee",MELB,2,"Ranged",RANB)
:Lbl MELB
:Disp "Enemy attacks!"
:If ARMDATA(1) < (int(20rand)+ENEMYDAT(5))
:Then
:SAVEDATA(3)-(int(6rand)+ENEMYDAT(6))üSAVEDATA(3)
:Disp "Enemy hits!"
:Else
:Disp "Enemy misses!"
:End
:Disp "You attack!"
:If ENEMYDAT(4) < (int(20rand)+ARMDATA(2))
:Then
:ENEMYDAT(3)-(int(10rand)+ARMDATA(3))üENEMYDAT(3)
:Disp "You hit!"
:Else
:Disp "You miss!"
:End
:Lbl RANB
:Disp "Enemy attacks!"
:If ARMDATA(1) < (int(20rand)+ENEMYDAT(5))
:Then
:SAVEDATA(3)-(int(6rand)+ENEMYDAT(6))üSAVEDATA(3)
:Disp "Enemy hits!"
:Else
:Disp "Enemy misses!"
:End
:Disp "You attack!"
:If ENEMYDAT(4) < (int(20rand)+ARMDATA(4))
:Then
:ENEMYDAT(3)-(int(8rand)+ARMDATA(5))üENEMYDAT(3)
:Disp "You hit!"
:Else
:Disp "You miss!"
:End
:End
:End
:End
:If SAVEDATA(3) ÷ 0
:DEATH
:Return
And here is the output:
Any help would be appriceated (note, some of the characters are wrong in the code listing)
It is getting tripped up with the While loop for some reason