user3812866
user3812866

Reputation: 149

Start() is not defined

Hey I am trying to create a simple text based slot machine with the view to convert it into a graphical one latter.

I have started by it prompting a menu which works fine. However when the user enters the required 'p' to continue it won't call the next function because I haven't defined it yet.... I have?

from time import sleep
from random import shuffle

#Creates the class
class Machine():
    #This is the constructor full of attributes
    def __init__(self):
        self.reel1 = ["Lemon", "Bell", "Cherry"]
        self.reel2 = ["Lemon", "Bell", "Cherry"]
        self.reel3 = ["Lemon", "Bell", "Cherry"]
        firstSlide = self.reel1
        secondSlide = self.reel2
        thirdSlide = self.reel3
        self.currentFunds = "10"
        funds = self.currentFunds
        f = open('score.txt', 'w')
        f.write(funds)

#Dictates all the funds and checks if the user has enough money or needs to add money
    def Funds(self):
        if self.currentFunds == "0":  
            print("You are out of credits! :( \n")
            Menu()


#Starts the spinning and randomizes the lists
    def Start(self, firstSlide, secondSlide, thirdSlide):
        shuffle(firstSlide, secondSlide, thirdSlide)
        print(firstSlide[0], secondSlide[1], thirdSlide[3])

#Intro Menu to give player stats and options
    def Menu(self):
        play = ""
        m = Machine()
        print('*****************\n')
        print('     WELCOME!  \n')
        print('*****************\n')
        print('Current Credits: ', m.currentFunds)
        if input("Press P to play \n") == "P" or "p":
            machine = Start()
            machine.Start()

machine = Machine()            
while True:
    machine.Menu()

Any ideas?

Upvotes: 0

Views: 150

Answers (1)

cwallenpoole
cwallenpoole

Reputation: 82028

You have Start as a member function of the Machine class. You need to replace machine = Start() with self.Start().

It actually looks like this is the case with a number of the variables you seem to be trying to use. For example, I would expect that Start would rely on self.start, but it is relying on parameters (which you are not passing in).


As a general comment on this code, I'm wondering if you really need/want to have this be structured this way. You seem to be creating the object recursively and I think you might be better off restructuring a bit.

Upvotes: 2

Related Questions