-1

I am making a small game, and i want to make a input checker.

Now when a user makes a message in my game, i want my game to check the message and if the message is nothing it wont make the message. Instead it will print out this:

msg1 = input ("\033[1;34;40mType a message: ") 

All until the user inputs a message that contains a character or a number. Now i have made my system of checking the message using functions, but it does not seem to work. It does what i told it to but when the user types something the message is nothing.

Here is my system:

def repeatmsg1():
    msg1_ = input ("\033[1;34;40mType a message: ") 
    if msg1 == "":
        msg1check()

    

def msg1check():
    msg1 = input ("\033[1;34;40mType a message: ") 
    if msg1 == "":
        repeatmsg1()


msg1 = input ("\033[1;34;40mType a message: ") 

if msg1 == "" :
    msg1check()
MaxD
  • 17
  • 7

1 Answers1

0

You can do it that way:

msg1 = False
while not msg1:
    msg1 = input("\033[1;34;40mType a message: ") 
print (msg1)
zvi
  • 3,677
  • 2
  • 30
  • 48
  • I will try, please wait. – MaxD Aug 16 '20 at 07:39
  • I got this error: IndentationError: unexpected indent – MaxD Aug 16 '20 at 07:40
  • 2
    so fix the indentation... – zvi Aug 16 '20 at 07:40
  • How do i do that? – MaxD Aug 16 '20 at 07:41
  • Just remove the spaces (I edited the answer, copy again the code). – zvi Aug 16 '20 at 07:42
  • Yes, you fixed it but when i run the game it asks me to type a message, i test it out by putting my message empty and it works. Now another problem shows up. When i type my message it prints it out like this: (username goes here): (message goes here) But when i use your code it prints the message and then the username, not even in the same line. – MaxD Aug 16 '20 at 07:48
  • so mark the answer as accepted and ask another question. – zvi Aug 16 '20 at 07:50
  • I found someone that answered my question much better, thank you on the help! – MaxD Aug 16 '20 at 07:52