How do I load a function with some code, inside another function exactly the same way?
or
How do I load global_variables()
correctly into my step1()
, and step2()
function without having to copy/paste it in each function?
def global_variables():
global txt
global option_a
global option_b
global option_c
global next_function_a
global next_function_b
global next_function_c
def step1():
global_variables()
txt = step1_text # fill with correct text
option_a = step1a_text
option_b = step1b_text
option_c = step1c_text
next_function_a = step1_1 # variable = call function
next_function_b = step2 # variable = call function
next_function_c = step5 # variable = call function
start_step() # call step function
def step2():
global_variables()
txt = step2_text # fill with correct text
option_a = step2a_text
option_b = step2b_text
option_c = step2c_text
next_function_a = game_over(step2c_text) # variable = call function
next_function_b = step3 # variable = call function
next_function_c = step2_1 # variable = call function
start_step() # call step function
I expect the:
global txt
global option_a
global option_b
global option_c
global next_function_a
global next_function_b
global next_function_c
to be included inside the step1()
, or step2()
function, just as if I would have copy/pasted it each time manually there.
# function to start at each new step
def start_step():
print(txt) # print story
attempt = False
choice = input('> ') # variable = user input prompt
if "A" in choice or "B" in choice or "C" in choice: # if-statement is '0' in variable (choice) or 1 then
step_end(choice)
else: # if-statement is other than 'A' or 'B' or 'C' then
game_over("Man, learn to type a letter.") # call dead function and show text message
def step_end(choice):
if choice =="A":
print(option_a)
next_function_a()
elif choice =="B":
print(option_b)
next_function_b()
elif choice =="C":
print(option_c)
next_function_c()
# function to exit program without errors by 'game-over' or 'winning' the game
def game_over(why): # function name (parameter)
print(why) # show argument ('why')
exit(0) # good normal exit without errors.