0

I'm real new to Python, and I'm trying to learn it through coding a small pet game, kinda like Tamagotchis. I'm starting with just doing a text-only game. My issue that I can't figure out is that when I show the stats (age, hunger, etc), I can't figure out how to specifically change the stat numbers without writing a new line, but while keeping the stat calculation processes separate (right now their ranges are the same until I get the code working, but eventually they will have separate delay ranges). I've tried looking up methods online, but the end="\r" has just been getting rid of either the entire age line, or just the hunger line.

Here's the basic bit I have right now (it's about mantises so ages go L1, L2, etc). Again, I'm a beginner, so I may not understand an answer unless it's explained/shown detailed.

def prAge1():
    age1 = "L1"
    print ("Age:", age1)
    while age1 == "L1":
        for _ in range(1):
            tdela1 = randint(5, 10)
        sleep (tdela1)
        age1 = 'L2'
        print ("Age:", age1)

def prHung1():
    hung1 = 50
    print ("Hunger:", hung1)
    while hung1 >= 0:
        for _ in range(1):
            tdelh1 = randint(5, 10)
        sleep (tdelh1)
        hung1 = hung1 - 5
        print ("Hunger:", hung1)

if __name__=='__main__':
    p1 = Process(target=prAge1)
    p1.start()
    p2 = Process(target=prHung1)
    p2.start()

Thanks!

  • Welcome to SO! It's good to mention your OS, but probably [curses](https://docs.python.org/3/howto/curses.html) is your answer. Short of that, I think printing backspaces are the main tool for rewriting part of a single line, but very likely this isn't enough for your use case. – ggorlen May 11 '20 at 14:56
  • 1
    Also, looking at your code, if you're launching two subprocesses, there's a race condition on the console. so there's a good chance they'll smush each other's output. Very likely, this should be a single process. Hard to say much beyond that without a bit more detials about what your expected behavior is. – ggorlen May 11 '20 at 15:06

0 Answers0