Hi. I've been trying to work out a way to reduce code in Applesoft.
E = user's choice
GL = amount of current gold
P(1) = price of item 1
K = an error check. K is set to 1 (K=1) when an invalid choice has been determined (“you can't afford/use it”). User is GOTOed to input new choice. Elsewise, K reset to 0, continue.
S = category identifier set at items list section S=1 (shields, line 750), S=2 (armour, line 900) or S=3(weapons, line 1200).
Here's what does work:
10 IF E = 1 AND GL < P(1) THEN GOSUB [PRINT “YOU CAN'T AFFORD IT"]: GOTO [ENTER NEW CHOICE]
20 IF E = 2 AND GL < P(2) THEN GOSUB [“YOU CAN'T...”]: GOTO [NEW CHOICE]
30 IF E = 3 AND GL < P(3) THEN GOSUB [“YOU CAN'T...”]: GOTO [NEW CHOICE]
40 IF E = 4 AND GL < P(4) THEN GOSUB [“YOU CAN'T...”]: GOTO [NEW CHOICE]
50 IF E = 5 AND GL < P(5) THEN GOSUB [“YOU CAN'T...”]: GOTO [NEW CHOICE]
I tried various ways of reducing the code above. This is what I currently have.
90 FOR A = 1 TO 5: IF E = A AND GL < P(A) THEN 100: NEXT
95 RETURN (to purchase?).
100 PRINT “YOU CAN'T AFFORD IT.”: FOR T = 1 TO 3500: NEXT: K = 1: RETURN
Running my program, if I enter choice 1 where the price should be 51 although I have 153 I get the “you can't afford it message.” If I interrupt the program (Ctr-C) at that point I get these values:
E = 1, P(A) = 0, GL = 153, P(1) = 51
P(A) seems to be the problem.
The issue is that I currently have 33 price error checks as IF/THEN statements. Surely, there must be a short routine that upon the user making a selection compares a variable from an array to a set variable to determine whether the array variable is less than a set variable. I just can't figure it out. Any help?