0

I'm working on a mini text role playing game where you must survive dinner with the king. I'm trying to basically declare the variables in the if statement making the variable a certain value based on what the user input. I'm thinking I need to declare them outside the functions but I'm not sure I'm fairly new to python.

def creation_role():
    print("""What is your character's role?\n
A: Lord (Base stats: Charisma  7, Wit 3, Valor 5)
B: Peaseant (Base stats: Charisma  5, Wit 7, Valor 3)
C: Knight (Base stats: Charisma  3, Wit 5, Valor 7)""")
    role = input("> ")
    role = role.lower()

    if "a" in role:
        role = "lord"
        charisma = 7
        wit = 3
        valor = 5
    elif "b" in role:
        role = "peaseant"
        charisma = 5
        wit = 7
        valor = 3
    elif "c" in role:
        role = "knight"
        charisma = 3
        wit = 5
        valor = 3
    else:
        error()
        creation_role()



def creation_home():
    print("""Choose where you hail from:\n
A. Hillford: Lush foliage as far as the eyes can see, the enchanted trees
bear the fruit of wisdom.\n
B. Aermagh: A land as beautiful as it is cold, it's people learn strength
from the first day of life fighting frostbite as a babe.\n
C. Venzor: The rich island nation some call it the pearl of Skystead,
In recent decades it's seen outsiders giddy to make quick riches.""")
    home = input("> ")
    home = home.lower()

    if "a" in home:
        home = "Hillford"
        wit + 2
    elif "b" in home:
        home = "Aermagh"
        valor + 2
    elif "c" in home:
        home = "Venzor"
        charisma + 2
    else:
        error()
        creation_home()

def test():
    creation_role()
    creation_home()
    print(home, "\n", charisma, "\n", wit, "\n", valor)

test()
martineau
  • 119,623
  • 25
  • 170
  • 301
  • Just make your function(s) return a `tuple` of values: i.e. `return (role, charisma, wit, valor)` I also suggest you read [Asking the user for input until they give a valid response](https://stackoverflow.com/questions/23294658/asking-the-user-for-input-until-they-give-a-valid-response). – martineau Mar 25 '19 at 02:33

2 Answers2

0

You should be creating class MiniText or something and then initialize these variable as part of init. Another problem I see is

charisma + 2

You are not storing result value

Vikrant Pawar
  • 789
  • 1
  • 6
  • 23
0

The test function doesn't know what the variables home, charisma, wit, and valor refer to.

In order for it to know about them, you'll need to return these values from your other functions. e.g.

def creation_role():
  ...logic
  return role, charisma, wit, valor

You can then use these variables from within test.

def test():
    role, charisma, wit, valor = creation_role()
    home, charisma, wit, valor = creation_home(charisma, wit, valor)
    print(home, "\n", charisma, "\n", wit, "\n", valor)

Note that you'll also need to modify the creation_home function to accept these variables, and return the new values.

def creation_home(charisma, wit, valor):
    ....
    return home, charisma, wit, valor

Edit: You also have some syntax errors when modifying the stats. It should be

wit += 2

instead of

wit + 2
gsuparto
  • 26
  • 4