Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  
Pages: 1 2 3 [4]

Author Topic: The Quest for Might and Knowledge: I have returned to programming  (Read 6226 times)

Rooster

  • Bay Watcher
  • For Chaos!!!
    • View Profile
Re: The Quest for Might and Knowledge: I have returned to programming
« Reply #45 on: April 10, 2010, 08:41:58 am »

I'll make a text adventure.
Also, if you happen to know python:
What do I need to do, to take values from keyboard like "y" or "n" ?
How then can I make the script check if it's the letter, adn if not do something else?
« Last Edit: April 11, 2010, 11:42:52 am by Rooster »
Logged

eerr

  • Bay Watcher
    • View Profile
Re: The Quest for Might and Knowledge: I have returned to programming
« Reply #46 on: April 10, 2010, 10:16:45 am »

« Last Edit: April 10, 2010, 10:18:54 am by eerr »
Logged

Berserker

  • Bay Watcher
    • View Profile
Re: The Quest for Might and Knowledge: I have returned to programming
« Reply #47 on: April 10, 2010, 01:19:53 pm »

I'll make a tet adventure.
Also, if you happen to know python:
What do I need to do, to take values from keyboard like "y" or "n" ?
How then can I make the script check if it's the letter, adn if not do something else?

You can use raw_input to take input from keyboard, but you have to press enter every time to accept the input and the user can type more than one letter.

Code: [Select]
def getkey(question=""):
    key = raw_input(question)  # Get the input
    return key[0:1]   # Return the first letter of the input


# How to use it:
print "Do you want to quit?"
print " y - Yes"
print " n - No"
print " ? - I don\'t know"
print " "

key = getkey("Select: ")

if key == 'y':
    print "You pressed y"

elif key == 'n':
    print "You pressed n"

elif key == '?':
    print "You pressed ?"

else:
    print "Invalid input."



If you are using Windows, and want only one character from the keyboard and without the need of pressing enter every time, you can download WConio and use it like this:
(If you use Python 2.6, click here to download WConio)
Code: [Select]
import WConio

print "Is this confusing?"
print " y - Yes"
print " n - No"
print " "

# key is a tuple which contains
# the ASCII number of the character
# and the character itself, like this: (49, '1') or (65, 'A')
# To take the character part of it, you just need to
# add the [1] at the end of the getch
key = WConio.getch()[1]

if key == 'y':
    print "You agree."
elif key == 'n':
    print "You disagree."
else:
    print "Invalid input."

Logged

eerr

  • Bay Watcher
    • View Profile
Re: The Quest for Might and Knowledge: I have returned to programming
« Reply #48 on: April 11, 2010, 08:58:12 pm »

Well, I'm not familiar with python except that it's somehow C or C++ based.

Perhaps you should familiarize everybody with pygame?
 ;)
Logged
Pages: 1 2 3 [4]