#πŸ”’ Sub 1,000 lines of code game

6 messages Β· Page 1 of 1 (latest)

shell bramble
#

I have recently started making this game (about 4-5 days). I just switched from using exclusively functions and global variables (bad i know) to a class, method, and function setup. This made the game about 10x as complicated but I was able to add cool stuff like character inventories in a simple way. Right now im looking for ways to clean up the code a bit as it seems maybe 30% of my code is repeating most of the same stuff besides a couple key words or making sure the user types in the correct input so the game does crash. Any suggestions / fixes / ideas are welcome! https://github.com/TheRealP4tton/TheBlacksmith

GitHub

My first python game. Contribute to TheRealP4tton/TheBlacksmith development by creating an account on GitHub.

marsh idolBOT
#

@shell bramble

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

shell bramble
#

for example this is an idea i use all throughout my code```python
print("You decided to craft an item of unknown quality...")
print(f"After many hours, you manage to craft a {newly_crafted.quality} {newly_crafted.name} that does {newly_crafted.damage} damage worth {newly_crafted.value} gold coins!")
print(f"You used {ingots_used} in the process")
print()
print(f"Would you like to sell it for {newly_crafted.value} or add it to your inventory?")
print("1. Sell")
print("2. Keep")
print()
choice = input("What would you like to do?")
os.system("cls")

while True:

    specific_input = ["1", "2"]

    if choice not in specific_input:
            print("You decided to craft an item of unknown quality...")
            print(f"After many hours, you manage to craft a {newly_crafted.quality} {newly_crafted.name} that does {newly_crafted.damage} damage worth {newly_crafted.value} gold coins!")
            print(f"You used {ingots_used} in the process")
            print()
            print(f"Would you like to sell it for {newly_crafted.value} or add it to your inventory?")
            print("1. Sell")
            print("2. Keep")
            print()
            choice = input("What would you like to do?")
            os.system("cls")
#

print a menu, if input not in specific input list that i make for each menu, print the menu again. Throw that in a while loop and it MAKES the character choose a proper input. Problem being it takes up 3x as many lines as it needs to

marsh idolBOT
#

@shell bramble

Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.