Trouble filling an array with LOOKUP for Hangman game
RLmiller777
Posts: 9
Im having trouble filling an array, then displaying it, for a Hangman game.
LOOKUP and filling an Array.....
Its the simple sub at the bottom. Not sure what to study in the book. I tried to use an example from the helpmenu but my program doesnt display anything, in fact it stops and wont run the rest. The last portion is not shown, its just simple subs that were working before the fillletters sub
Thanks in advance for advice.
' {$STAMP BS2}
' {$PBASIC 2.5}
PAUSE 1000
Letters VAR Bit(25) ' remember zero and there are 26
GuessedLetters VAR Bit(25)
counter VAR Nib
iidx VAR Byte
result VAR Byte
'get_a_guess
'displayUsedLetters
'displayLettersLeft
'GoodOrBadGuess
'CheckWinOrLose
Begin: 'Main Program
GOSUB fillletters
GOSUB displayHeader
GOSUB displayhead
GOSUB displayNeck
GOSUB displayLeftarm
GOSUB displayRightarm
GOSUB displayTorso
GOSUB displayLeftleg
GOSUB displayRightleg
GOSUB displayHung
GOSUB displayWinner
END ' Main Program
'*********************************************************
fillletters:
FOR counter = 0 TO 25
LOOKUP counter, ["abcdefghijklmnopqrstuvwxyz"],result
GuessedLetters(counter)=result
NEXT
FOR counter = 0 TO 25
DEBUG ASC? GuessedLetters(counter), CR
NEXT
RETURN
'*********************************************************
LOOKUP and filling an Array.....
Its the simple sub at the bottom. Not sure what to study in the book. I tried to use an example from the helpmenu but my program doesnt display anything, in fact it stops and wont run the rest. The last portion is not shown, its just simple subs that were working before the fillletters sub
Thanks in advance for advice.
' {$STAMP BS2}
' {$PBASIC 2.5}
PAUSE 1000
Letters VAR Bit(25) ' remember zero and there are 26
GuessedLetters VAR Bit(25)
counter VAR Nib
iidx VAR Byte
result VAR Byte
'get_a_guess
'displayUsedLetters
'displayLettersLeft
'GoodOrBadGuess
'CheckWinOrLose
Begin: 'Main Program
GOSUB fillletters
GOSUB displayHeader
GOSUB displayhead
GOSUB displayNeck
GOSUB displayLeftarm
GOSUB displayRightarm
GOSUB displayTorso
GOSUB displayLeftleg
GOSUB displayRightleg
GOSUB displayHung
GOSUB displayWinner
END ' Main Program
'*********************************************************
fillletters:
FOR counter = 0 TO 25
LOOKUP counter, ["abcdefghijklmnopqrstuvwxyz"],result
GuessedLetters(counter)=result
NEXT
FOR counter = 0 TO 25
DEBUG ASC? GuessedLetters(counter), CR
NEXT
RETURN
'*********************************************************
Comments
As for the DEBUG, GuessedLetters() is a bit, 0 or 1, and there is no ASC value for them. The lowest displayable ASC value is 32. Here too you will need to translate the bits, 0 or 1, into the letters, but that is pretty easy. Use capital letters, which start at 65 for A and add it to counter as you loop through the GuessedLetters() array.
For the input, you could "translate" the letter input to a bit position: