Ask coding questions

← Back to all posts
How do I make it so that there is a developer mode?
Jrb12 (0)

I was wondering if there was a way in Python to make it so if I pressed a button it would allow you to type in which section you wanted to go to in my game. For instance, if I had a section called BossFight(), I would want to be able to press 7 on my keyboard and it would say "Where would you want to go?" and I would type that section and it would play that section. Bit of a long shot but wondering if I could make it happen

Answered by Bookie0 (6289) [earned 5 cycles]
View Answer
Jrb12 (0)
Bookie0 (6289)

Well you could ask them which section, they type something, and based on what they type, call the function BossFight():

go = input("Where would you want to go?") # input to ask user

if go == "7": # conditionals to determine what user wants to do
  BossFight() # calls BossFight function

Is this what you wanted? :)

Jrb12 (0)

@Bookie0 That's perfect, but is there a way to call this input by pressing a key on your keyboard?

Bookie0 (6289)

@Jrb12 sure, you can use getch():

import getch

print("Where would you want to go?")

go = getch.getch() # user only has press one key and no need to click enter

if go == "7": # conditionals to determine what user wants to do
  BossFight() # calls BossFight functio
Bookie0 (6289)

@Jrb12 no problem! mark as correct answer (if it helped :)?

Jrb12 (0)

So how exactly do I run this in code? So basically, how do I make it so the orange arrow appears? (i don't know if that's what it's called)

Bookie0 (6289)

@Jrb12 well just add go = getch.getch() where you want the user to be able to change to dev mode. And by orange arrow, do you mean this?

You won't be able to make it appear, but you can copy paste it and add it in a print statement I guess.

Bookie0 (6289)

No problem! Glad it helped! :) @Jrb12

JamesGordon1 (150)

you could do a multithreading and have the other thread running getch and watching for 7 being pressed then interrupting the main program and then doing something like this:

goto = input("Where would you like to go: ")
if (goto == #whatever you want):
#this next bit is if you want more then one thing
elif (goto == #whatever you want):
    #anything else you want