Announcement

Collapse
No announcement yet.

EOF:Error when waiting for input, Python editor scripting

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    EOF:Error when waiting for input, Python editor scripting

    Hello, I'm working on some scripts in Python for the UE editor. Right now I've been succesfull with some scripts, like loading assets and replacing actors in the map level.
    Now I'm trying to output a console menu, so I can launch some functions from the Cmd console, failing over and over. Can you guys help me ?
    Here's the code:
    Code:
    def sayHello():
       print("Hello World")
    def quitMenu():
       return
    inputKey = -1
    switcher = {
       1: sayHello,
       0: quitMenu
    }
    while inputKey != 0:
       print("\nWelcome to a Python menu, select an option:")
       print("0: Quit")
       print("1: Say hello")
       inputKey = int(raw_input())
       func = switcher[inputKey]()
    And this is the error message I'm getting all the time.

    Code:
    LogPython: Error: EOFError: EOF when reading a line
    Replies would be much appreciated!

    PS: I saw another comment with the same issue, however I'm using v4.20 and isn't working anyways.

    #2
    Hey, I think this is just a limitation of the way the console UI in the Editor works. It's not exactly like an interactive Python console that you might run in a command line. I'd be really surprised if it's possible for a script to prompt for input directly in that way.

    Could you accept the choice as a parameter, like this:

    Code:
    def sayHello():
       print("Hello World")
    def quitMenu():
       return
    inputKey = -1
    switcher = {
       1: sayHello,
       0: quitMenu
    }
    def menu(choice=0):
        if int(choice):
            func = switcher[int(choice)]()
        else:
            print("\nWelcome to a Python menu, pass an option:")
            print("0: Quit")
            print("1: Say hello")
    then call it as

    Code:
    menu(1)
    or, to see the options, call just

    Code:
    menu()

    Comment

    Working...
    X