vendredi 15 décembre 2017

Python - one if of a "while" loop works only once (at the beginning)

the "if pulses > 20 and spinning == 0" only works once at the beginning of the script, after "one" spin by pressing the spin-button (input_state == False) the if segment doesnt work anymore (after the variable "isSpinning" is set to 0) in contrast to all the other if segments like: "if input_state2 == False and credits > 0 and spinning == 0" (works).

while mode == "normal":



input_state2 = GPIO.input(18)
if input_state2 == False and credits > 0 and spinning == 0:
    print('Auszahlung')
    os.system('killall omxplayer.bin')
    Popen(['omxplayer', '-b', 'wof_alarm.mp3'])
    lcd_string(" HANDAUSZAHLUNG " ,LCD_LINE_1)
    lcd_string("Team rufen (" + str(credits) + " )",LCD_LINE_2)
    credits = 0
    auszahlung = 1

if pulses > 20 and spinning == 0:
    print('I bims 1 Muenze')
    credits = credits + 1
    lcd_string("Credits: " +  str(credits),LCD_LINE_2)
    pulses = 0



input_state = GPIO.input(4)
if input_state == False:
    print('Knopf gedruckt, pruefe credits')
    if credits > 0 and spinning == 0:
        os.system('killall omxplayer.bin')
        print('Credits sind da, drehe')

        spinning = 1


        lcd_string("Credits: " +  str(credits),LCD_LINE_2)
        print('Neue Credits ' + str(credits))
        #randomNummer = 7 #Nur zu Testzwecken aktivieren!!
        randomNummer = numpy.random.choice(numpy.arange(2, 13), p=[0.2, 0.02, 0.02, 0.05, 0.2, 0.05, 0.01, 0.2, 0.05, 0.01, 0.19])
        print("Es wurde als Nummer gewaehlt:" + str(randomNummer))
        Popen(['omxplayer', '-b', 'wof_spin_halloween.mp3'])
        lcd_string("Viel Glueck!",LCD_LINE_2)
        Spin()

        if randomNummer == 2:
            goTo2()
            os.system('killall omxplayer.bin')
            Popen(['omxplayer', '-b', 'wof_lose.mp3'])
            lcd_string("KEIN GEWINN!",LCD_LINE_2)
            time.sleep(2)
            lcd_string("Credits: " +  str(credits),LCD_LINE_2)


        elif randomNummer == 3:
            goTo3()
            os.system('killall omxplayer.bin')
            Popen(['omxplayer', '-b', 'wof_bonus.mp3'])
            lcd_string("** BONUSGAME`**",LCD_LINE_2)
            time.sleep(2)
            lcd_string("Credits: " +  str(credits),LCD_LINE_2)
            #bonusgame = 1 #ACHTUNG SPINNING MUSS NACH BONUSGAME NOCH AUF 0 GESETZT WERDEN!!!!!
            timbb = 8

        elif randomNummer == 4:
            goTo4()
            os.system('killall omxplayer.bin')
            Popen(['omxplayer', '-b', 'wof_great.mp3'])
            credits = credits + 4
            lcd_string("2 EURO GEWINN!",LCD_LINE_2)
            time.sleep(2)
            lcd_string("Credits: " +  str(credits),LCD_LINE_2)
            timbb = 8

        elif randomNummer == 5:
            goTo5()
            os.system('killall omxplayer.bin')
            Popen(['omxplayer', '-b', 'wof_50.mp3'])
            credits = credits + 1
            lcd_string("0.50 EUR GEWINN",LCD_LINE_2)
            time.sleep(2)
            lcd_string("Credits: " +  str(credits),LCD_LINE_2)
            timbb = 10
        elif randomNummer == 6:

            goTo6()

            os.system('killall omxplayer.bin')
            Popen(['omxplayer', '-b', 'wof_lose.mp3'])
            lcd_string("KEIN GEWINN!",LCD_LINE_2)
            time.sleep(2)
            lcd_string("Credits: " +  str(credits),LCD_LINE_2)

        elif randomNummer == 7:
            goTo7()
            os.system('killall omxplayer.bin')
            Popen(['omxplayer', '-b', 'wof_again.mp3'])
            lcd_string("**FREESPIN**",LCD_LINE_2)
            sleep(2)
            lcd_string("Credits: " +  str(credits),LCD_LINE_2)
            freespin = 1
            timebb = 8

        elif randomNummer == 8:
            goTo8()
            os.system('killall omxplayer.bin')
            Popen(['omxplayer', '-b', 'wof_toxic.mp3'])
            if credits == 0:
                credits = 3
                lcd_string("CREDIS x3",LCD_LINE_2)
                time.sleep(2)
                lcd_string("Credits: " +  str(credits),LCD_LINE_2)
            else:
                credits = credits * 3

                lcd_string("CREDIS x3",LCD_LINE_2)
                time.sleep(2)
                lcd_string("Credits: " +  str(credits),LCD_LINE_2)
            timebb = 8
        elif randomNummer == 9:
            #LOSE
            goTo9()
            os.system('killall omxplayer.bin')
            Popen(['omxplayer', '-b', 'wof_lose.mp3'])
            lcd_string("KEIN GEWINN!",LCD_LINE_2)
            time.sleep(2)
            lcd_string("Credits: " +  str(credits),LCD_LINE_2)
        elif randomNummer == 10:
            goTo10()
            os.system('killall omxplayer.bin')
            Popen(['omxplayer', '-b', 'wof_50.mp3'])
            credits = credits + 1
            lcd_string("0.50 EUR GEWINN",LCD_LINE_2)
            time.sleep(2)
            lcd_string("Credits: " +  str(credits),LCD_LINE_2)
            timbb = 8
        elif randomNummer == 11:
            goTo11()
            os.system('killall omxplayer.bin')
            Popen(['omxplayer', '-b', 'wof_great.mp3'])
            credits = credits + 10
            lcd_string("5.00 EUR GEWINN",LCD_LINE_2)
            time.sleep(2)
            lcd_string("Credits: " +  str(credits),LCD_LINE_2)
            timbb = 8
        elif randomNummer == 12:
            goTo12()
            os.system('killall omxplayer.bin')
            Popen(['omxplayer', '-b', 'wof_50.mp3'])
            credits = credits + 1
            lcd_string("0.50 EUR GEWINN",LCD_LINE_2)
            time.sleep(2)
            lcd_string("Credits: " +  str(credits),LCD_LINE_2)
            timbb = 8
        sleep(timebb)
        timebb = 5
        ResetToStart(randomNummer)
        lcd_string("Credits: " +  str(credits),LCD_LINE_2)
        spinning = 0

    else:
        print('Nicht genug credits')

Aucun commentaire:

Enregistrer un commentaire