Question:
Hi, I’ve been creating a text-based game using Python, and I created a function called walk( ), which prompts the user to walk in a direction.
However, the prompt does not appear when I call the function and the code continues to the next line.
Repl link:
https://replit.com/@NateDhaliwal/Text-based-adventure-game?s=app
Code snippet:
walkdir=None
def walk():
walkdir=None
while walkdir!=None:
walkdir=int(input('''1 - Walk forwards
2 - Walk left
3 - Walk right
4 - Walk backwards
'''))
if walkdir==1:
print('Walking forwards...')
elif walkdir==2:
print('Walking left...')
elif walkdir==3:
print('Walking right...')
elif walkdir==4:
print('Walking backwards...')
else:
walkdir=None
def exitCS():
from quests import listOfQuestsArk
exitcs=int(input("""You are at the exit of the City Square. There is nothing left to do here. Do you want to leave? You can always come back by entering 'CS' when prompted to walk.
1 - Yes
2 - No
"""))
if exitcs==1:
print('Left City Square. \n Quest completed: City Square meet up')
listOfQuestsArk.remove('City square meet up')
elif exitcs==2:
print('Staying at City Square. To leave City Square, walk forward.')
walk()
coins=300
sword=None
shield=None
import time, os
print('''Character stats:
Health - 200
Sanity - 100
Strength - 250
Influence - 50
Observation - 100
Lore - 50
Stamina - 150
''')
time.sleep(5)
os.system('clear')
print('You are spawning at the City Square. Please wait a moment. Coins:',coins)
time.sleep(2)
os.system('clear')
print('Spawned!')
walk()
print('You meet a trader, Kalan.')
ttkalan=int(input('''1 - Talk
2 - Continue walking
'''))