I've been trying to make a hangman game where if the command "!hangman" is iniated, this code will execute:
def cmdHangman(event):
print("!hangman") #this print works
type("Game: Hangman")
type(Key.ENTER, Key.SHIFT)
Hangman.Playing()
Where Hangman.Playing()
leads to:
listOfWords = ["example", "says", "python", "rocks"]
guessWord = random.choice(listOfWords)
board = [" * " for char in guessWord]
alreadySaid = ""
class Hangman():
def Playing():
print("Playing") #print not showing
global guessWord, board, alreadySaid
whatplayersaid = hangmanRegion.text()
hangmanRegion.stopObserver()
if whatplayersaid in guessWord:
board = [char if char == whatplayersaid or char in alreadySaid else " * " for char in guessWord]
board = "".join(board)
type(board)
type(Key.ENTER)
else:
type("Nope")
type(Key.ENTER)
alreadySaid = alreadySaid + whatplayersaid
Hangman.PlayBuffer()
def gotoPlaying(event):
print("gotoPlaying") #print not showing
Hangman.Playing()
def PlayBuffer():
print("PlayBuffer") #print not showing
wait(1)
hangmanRegion.onChange(Hangman.gotoPlaying)
hangmanRegion.observe(FOREVER)
It should scan the next chat input for letters using hangmanRegion.text(), so if someone in the groupchat types: "A", whatplayersaid
should equal "A"
The weird thing, it doesnt even work. At all.
There is no error log or anything. I tried putting prints everywhere in class Hangman()
and I didn't see any of the prints in the log.
Could someone pinpoint a flaw in my code? Is it not being executed or is Sikuli IDE glitching out? Or am I just really tired?
Log after typing the command:
!hangman
[log] TYPE "Game: Hangman"
[log] ( Shift ) TYPE "#ENTER."