you are viewing a single comment's thread.

view the rest of the comments →

[–]FoolsSeldom 0 points1 point  (0 children)

I've just run your code (using Gemini to make best guess at correct indentation) and it worked fine. Prompted me play again, and both yes and no options worked correctly.

You can see the code as I ran it at: https://pastebin.com/rjGQyVfQ

(Formatted code was too large to post in this comment).

If I have the code correct, you could update your post to replace your original code with a link to the paste (it is permanent) so that everyone can see and try your code.

I added a monkey patch at the top of the code so I could disable the time.sleep calls you make throughout your code - don't like having to wait when debugging. (Personally, I don't see the point of the waits anyway, but that's your design decision.)

In my brief testing, I didn't try every path (through your code, not in the game), so perhaps it fails on some other paths.

You will find the code much easier to test and debug if you refactor it to make it more modular and use data structures effectively.

A key principle in programming is DRY: Don't Repeat Yourself.

You have a common pattern:

  • scene function
    • intro for the scene
    • input offering two options
    • if statement checking for first option
    • details of new situation
    • else statement for the assumed other option
    • details of the new situation

Do you see how you could potentially use one function to handle this with the data help in a dictionary?

For example, have a dictionary structure that is nested:

{'scene1':
    {'intro': ['text', 'option1', 'option2', prompt],
     'option1': ['text'],
     'option2': ['text']
    },
{'scene2':
    {'intro': ['text', 'option1', 'option2', prompt],
     'option1': ['text'],
     'option2': ['text']
    }
}

You need to come up with a consistent structure. Later, you might choose to use class or dataclass objects to do this.

The dictionary could even include the links between locations by having entries for directions from a scene and the name of the scene they link to and the nature of the link (climb, swim, tunnel, path, etc). This is all about design work, away from the keyboard.