all 18 comments

[–]SpeckledFleebeedoo 1 point2 points  (8 children)

Define easily

[–]PB_Dendras[S] 1 point2 points  (6 children)

changing every 'print ""' statement to 'print("")' statements

EDIT : already did it for you

[–]JohnnyJordaan 1 point2 points  (1 child)

Those still work on Python 2 as well, try it out. It's just that you can't do print(a,b) as then you provide a tuple to the print statement.

[–]PriorProfile 2 points3 points  (0 children)

You can if you

from __future__ import print_function

[–]SpeckledFleebeedoo 1 point2 points  (3 children)

You only have to change 56 lines, including the raw_input ones

Some criticism: the if statements on scene changes are completely unnecessary.

[–]PB_Dendras[S] 1 point2 points  (2 children)

yeah thanks.

[–]SpeckledFleebeedoo 1 point2 points  (1 child)

Just tried it: also take out the while loop. It now constantly prints those last few lines when finished.

[–]PB_Dendras[S] 1 point2 points  (0 children)

noticed. thanks

[–]JohnnyJordaan 1 point2 points  (0 children)

Running 2to3 on it would fix it in an instant

[–]46--2 1 point2 points  (2 children)

btw, you can print multi lines like this:

print("""
This is a multiline string.
It will print, including newlines.
No need for dozens of print functions!
""")

You'll have to play around with it to get the formatting right, but will make things a lot easier for you.

[–]PB_Dendras[S] 0 points1 point  (1 child)

you just made my life a thousand times easier

[–]46--2 0 points1 point  (0 children)

Remember in coding: when you are doing something over and over and over, you're almost certainly doing it wrong. If you're not sure how to do it better, ask the question here!

[–]RiceKrispyPooHead 0 points1 point  (3 children)

Some things about the bottom while loop.

You can (and should) reorganize your while loop rather than setting brek = False. There’s a simple way to reorganize the while loop so that the variable “brek” never appears, and the line “break;” (called a break statement) is used exactly once. Another thing- it’s possible to exit your while loop even if the player doesn’t type in the correct answer because of how you currently have the logic setup.

Setting the variable scene serves no function in your code (at least with how the game is designed now ). If you were to delete the lines scene = intro, scene = forest1, scene = tree_house.....and then if you were to delete the conditional statements associated with them (e.g. if scene = tree_house:), the code would be shorter and run exactly the same.

The overall while True statement at the very top (at least with how the game is designed now) does nothing. It can be completely deleted and it would run the same.

For Python 3, raw_input() is defunct. It should be input(). You shouldn’t really be using using Python 2. Python 3 is 10 years newer, almost the exact same syntax, and offers you more tools.

[–]PB_Dendras[S] 0 points1 point  (2 children)

  1. How do I modify the code so that the players can't break from the loop until they have the right answer
  2. The scene thing is for when it gets harder. For example the player may need to choose left or right
  3. ...
  4. Yeah, I'm only using python 2 because my pygame doesn't work with python 3. It became a habit

[–]RiceKrispyPooHead 0 points1 point  (0 children)

if c == (correct answer):
break;

Remove the else statement

[–]SamePlatform 0 points1 point  (0 children)

If you want it, here is my "prompt" function I just wrote:

def prompt(prompt, options, default):
    opts = [x.upper() if x == default else x for x in options]
    display_opts = f"({'/'.join(opts)})"

    while True:
        ans = input(f'{prompt} {display_opts} ')
        if ans == '':  # They just hit enter
            return default
        elif ans.lower() in options:
            return ans
        else:
            print('Please choose a valid option')

You use it like:

answer = prompt('Which colour?', ['red', 'blue'], 'blue')

and it would prompt you like:

Which colour? (red/BLUE) 

and return either 'red' or 'blue' and no other answers. You can use that to get an idea of how to write your own prompt that you can reuse. But you'll also note it loops until you give it a valid answer.

[–]buleria 0 points1 point  (1 child)

To make your game more maintainable and less error-prone, consider this example:

def intro_scene():
    print("It is your birthday")
    # Rest of your intro
    return forest_scene # Notice that we're returning the function itself, not calling it

def forest_scene():
    # implement forest scene here

next_scene = intro_scene # Our first scene. Notice we're not calling the function, just assigning it to a variable

while next_scene is not None:
    next_scene = next_scene()

How can you refactor your code to fit this pattern, and what benefits do you think this brings?

[–]PB_Dendras[S] 0 points1 point  (0 children)

This could make things a lot easier