-2

I am making a Cookie clicker like game in Python, and I am trying to have the while loop keep going so it checks if a second has gone (so it adds "cookies") while still looking if the user is making an input (clicking on "Cookie").

Whenever I try this it waits for the input instead of doing the rest of the loop.

This is what my current code looks like (There's more of course):

While True:
    console.clear()
    cookieText = "You have " + str(cookies) + " cookies"
    print cookieText
    clicker = raw_input("")
    if clicker == "":
        cookies += clickerPower
    more...

This is what I want to add:

While True:
    last = time()
    if last == timer:
        timer = last
        more...

2 Answers2

0

this worked for me (source)

import msvcrt

num = 0
done = False
while not done:
    print num
    num += 1

    if msvcrt.kbhit():
        print msvcrt.getch()
        done = True
Community
  • 1
  • 1
jake77
  • 1,892
  • 2
  • 15
  • 22
0

The answer is threading. But it's not simple.

Laszlowaty
  • 1,295
  • 2
  • 11
  • 19