-3

Ok, so I am trying to set a bool so that if an item is taken it becomes True and next time if it is True then it takes a different path, it's my first time writing something in Python so excuse the bad code conventions. Anyways, I need the bool to be False until the note is taken, and when it is I want it to become True. One problem I will probably have in the future is that in one part the player comes back to this room, how can I keep the bool True for when they do?

def first_room(Note):
    choice1_1 = raw_input('The house looks much larger than it did from the outside. You appear in a room, to your left is a closet, to your right is a pile of junk, in front of you is a door, and behind you is the exit.')
    choice1_1 = choice1_1.lower()
    if choice1_1 == 'left' or choice1_1 == 'l' or choice1_1 == 'closet':
        if note == False:
            choice1_c = raw_input('You open the closet and check inside, there is a note. Do you take the note? (Y/N)')
            choice1_c = choice1_c.lower()
            if choice1_c == 'y':
                print 'You took the note.'
                first_room(True)
            if choice1_c == 'n':
                print 'You leave the note alone.'
                first_room(False)
        else:
            print 'The closet is empty.'
            first_room(True)
first_room(False)
user2495853
  • 1
  • 1
  • 3
  • 2
    Case matters in Python. `def first_room(Note)` and `def first_room(note)` are not the same thing. –  Jun 18 '13 at 05:49
  • You seem to be trying to use function calls as GOTO's. This is a bad idea because it won't work the way you want/expect it to. – John La Rooy Jun 18 '13 at 05:55
  • Welcome to Stack Overflow. Please read the [FAQ] soon. I've tidied up the indentation of the code for you (avoid tabs on SO; they cause trouble). The only line I'm not sure about is the very last one, the `first_room(False)`. It might be meant to be part of the function or it might be a separate statement after the function (or it might be intended to come after an `else:` for the first `if`). Please edit the function if I chose the wrong indentation. – Jonathan Leffler Jun 18 '13 at 05:55
  • @JonathanLeffler, pretty sure the last line should be dedented – John La Rooy Jun 18 '13 at 06:01
  • @gnibbler: given the OP's edit, it appears you were correct. – Jonathan Leffler Jun 18 '13 at 06:09

2 Answers2

2

Several problems here:

First, you formulate your question assuming the whole world is familiar with the context you are working in. Well, we aren't. :-) Somehow it looks like you want the function to remember the value of note, but I am not sure.

More problems:

def first_room(Note):

in Python, class names begin with uppercase, variable names should begin with lowercase.

if note == False:

Never, ever do this! You can test a Boolean directly, like:

if not note:

You can also swap the two arms of the if to make it sound less silly:

if note:
    # ... do something ...
else:
    # ... do something else ...

In any case I would recommend you attend a basic programming course...

András Aszódi
  • 8,948
  • 5
  • 48
  • 51
  • In my situation, I can't attend a programming course. Parents won't allow it. I only started with Python yesterday and previously all I knew was some visual basic, either way thanks for the help. It works, I had just accidentally wrote Note instead of note, didn't mean to. Also, just curious about the "if not note:" thing, haven't seen that used. Does "if note:" test if it's true? – user2495853 Jun 18 '13 at 06:01
  • Glad that you started learning Python, it is a very nice language and will help you master general programming concepts. Apart from the official documentation, you probably know about [Dive into Python](http://www.diveintopython.net) which is an excellent introduction to the language. Last advice: don't bother with Python 3 just yet, Version 2 is fine. Good luck! – András Aszódi Jun 18 '13 at 08:49
0

You need some kind of datastructure to store the state of the rooms. A dict is probably a good choice

eg:

rooms = {}
rooms['first_room'] = {'note': False}

Then you can inspect the state of the note like this

if rooms['first_room']['note']:
    ...

and update it like this

rooms['first_room']['note'] = True

At this stage of your learning, don't be afraid to make rooms a global variable

John La Rooy
  • 295,403
  • 53
  • 369
  • 502
  • Was just looking at the dict concept today, still kind of hazy, taking the lessons at another site and I'm only about 5/12 of the way through. Thanks for the help! – user2495853 Jun 18 '13 at 06:02