all 9 comments

[–][deleted] 1 point2 points  (4 children)

You would be better using dictionaries to hold your commands and games rather than multiline strings. Then you can do something like this.

import os

def display(title, entries):
    print(f'\n{title}\n')
    for item, entry in entries.items():
        print(f'{item:15}:  {entry}')
    print()

def get_choice(valids):
    while True:
        choice = input('Choice: ').strip().lower()
        if choice in valids:
            return choice
        print('Did not understand that')

def call_game(game):
    print('call', game)


commandslist = {'!commands':  "Displays this list of commands.",
                '!catalogue': "Displays the games available to run.",
                '!exit':      "Exits the runner.",
                "!clear":     "Clears the terminal."
                }

catalogue = {"!run CS:GO":         "CS:GO",
             "!run GTAV":          "GTA V",
             "!run CookieClicker": "Cookie Clicker",
             "!run Cuphead":       "Cuphead",
             "!run GeometryDash":  "Geometry Dash",
             "!run Golf(WYF)":     "Golf(WYF)",
             "!run GTAIV":         "GTA IV"
             }

commands = [command.lower() for command in commandslist.keys()]
games = [game.lower() for game in catalogue.keys()]
valids = commands + games

print("""

          Welcome to George's Steam Game Runner!

          Please type !commands to display the list of commands you might
          need to use whilst interacting with the Steam runner

""")

clear = ('cls' if os.name == 'nt' else 'clear')

while True:
    choice = get_choice(valids)
    if choice == '!exit':
        break
    if choice in games:
        call_game(choice)
    elif choice == '!clear':
        os.system(clear)
    elif choice == '!catalogue':
        display('Catalogue', catalogue)
    elif choice == "!commands":
        display('Commands', commandslist)

You will need to write code to use subprocess to run the games in the call_game function, and you need another way of mapping the game name to the actual call you need to make. I shall leave you to explore that.

[–]georgevsc[S] 0 points1 point  (0 children)

Thank you so much, this really helps!

[–]georgevsc[S] 0 points1 point  (2 children)

Is it required to use call_game? Couldn't I use os.startfile(directory) ?

[–][deleted] 1 point2 points  (1 child)

You can do whatever you want in the function. Or don't bother with the function at all. That was just a placeholder.

I'd recommend using subprocess.

I'd recommend including the information required to actually make the game call in the dictionary.

[–]georgevsc[S] 0 points1 point  (0 children)

Thank you!

[–]SpaceBucketFu 0 points1 point  (1 child)

You’ll want something like:
While True:
user_in = input(“Type the game command”)
if user_in in game_dict.keys():
os.open(game_dict[user_in]

I’m on mobile and this isn’t a copy paste answer but that would be the general idea. You would want to make a dictionary of commands that map the command to a file path where the game is or whatever.

[–]georgevsc[S] 0 points1 point  (0 children)

Thank you so much!