Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
List Identification
#1
Hello! I've gotten back into python coding, and have been coding a text game, here is the code.

#imports here
import random
import time

#all the variables - lets go!
health = 20
coins = 700

shop_buy_options = ["Lapis Helmet","Lapis Chestplate","Lapis Leggings","Lapis Boots","Hardened Diamond","Young Dragon Fragment","Diamond Helmet","Diamond Chestplate","Diamond Leggings","Diamond Boots","Speed Talisman"]
shop_forge_options = ["Reforged Iron Helmet","Reforged Iron Chesplate","Reforged Iron Leggings","Reforged Iron Boots","Reforged Iron Sword","Diamond Helmet","Diamond Chestplate","Diamond Leggings","Diamond Boots", "Diamond Sword","Hardened Diamond Helmet","Hardened Diamond Chestplate","Hardened Diamond Leggings","Hardened Diamond Boots", "Hardened Diamond Sword","Young Dragon Helmet","Young Dragon Chestplate","Young Dragon Leggings","Young Dragon Boots","Dragon Slayer Sword","Aether Shell"]

location = ["base"]
two_location = ["Spider's Den","Coal Mine","Wheat Fields"]

armor_number = 0
inventory = ["Iron_Sword","Chainmail Helmet","Chaimail Chestplate", "Chainmail Leggings", "Chainmail Boots"]

#skill levels
combat_skill = 0
mining_skill = 0
farming_skill = 0

name = input("Enter your username:")

#player data
player_data_1=open(name, "w")
player_data_1.close()

input("""
Welcome to Dungeon Run!

This is a fighter game all about getting the best armor and weapons to kill the Aether Dragon.
There are many things for you to explore!


Note: Exact spelling is necessary!
    """)

input("As a gift of being a new adventurer, I will give you a full set of chaimail armor and a standard sword.")

def console_main():
    def console():
        global console_command
        #global location
        global mining_skill
        global farming_skill
        global combat_skill
        global shop_buy_options
        global shop_forge_options
        global inventory
        
        console_command = input("Enter a command. Type /q for the list of all possible commands.")
#routine updates
        
        player_data_1=open(name, "w")
        for element in inventory:
            player_data_1.write(element)
        player_data_1.close()

      #  if "Iron Chestplate" in inventory


#functions
        if console_command == "/q":
            print("""
    /q: list all commands
    /e: list inventory
    /r: return to base
    /m: mine(if applicable)
    /l: list warp opprotunities and warp
    /s: access the shop (if at the base)
    /d: drop an item
    /qu: save and quit
    /location: list current location
    /skill: display all skill levels
    """)
        if console_command == "/skill":
            print("Mining Skill: ",mining_skill)
            print("Farming Skill: ",farming_skill)
            print("Combat Skill: ",combat_skill)

        if console_command == "/e":
            print(inventory)

        if console_command == "/location":
            print(location)

        if console_command == "/r":
            del location[:]
            print (location)
            location.append("base")
            ("base")
            print ("You are at ",location)

        if console_command == "/l":
            print("Choose which location to warp to.")
            del location[:]
            location.append(input("Coal Mine, Spider's Den, Wheat Fields"))
            print ("You are at ",location)


        if console_command == "/m":
            
            if location == "Coal Mine":
                mining_skill = mining_skill =+ 5
                mining_randomness = random.randint(1,101)
                if mining_randomness > 70:
                    inventory.append("Coal")
                    print("You found Coal!")
    
                    time.sleep(2)


        if console_command == "/qu":
            exit()

        if console_command == "/d":
            drop_item = input("Drop which item?")
            inventory.remove(drop_item)
            print("You dropped one ",drop_item)

#shop code
            
        if console_command == "/s" and location == "base":
            print(location)
            print("Welcome to the shop! Here you can forge things, sell others, and buy yet others!")
            shop_options = input("""

Buy
Sell
Forge""")

            if shop_options == "Buy":
                global coins
                print("You have ",coins," coins in your account")
                print("A catalog of all available items to buy (Prices are displayed when you open an item): (type /n to not buy anything")
                shop_buy = input(shop_buy_options)

                if shop_buy == "Lapis Helmet":
                    buy_confirm_lapis_helmet = input("Type Y / N to confirm order. Price: 500 coins")

                    if buy_confirm_lapis_helmet == "Y" and coins > 500:
                        inventory.append("Lapis Helmet")
                        coins = coins - 500
                        print("You bought a Lapis Helmet!")
                    else:
                        return
                    
                if shop_buy == "Lapis Chestplate" and coins > 800:
                    buy_confirm_lapis_chestplate = input("Type Y / N to confirm order. Price: 800 coins")

                    if buy_confirm_lapis_chestplate == "Y":
                        inventory.append("Lapis Chestplate")
                        coins = coins - 800
                        print("You bought a Lapis Chestplate!")
                    else:
                        return

                if shop_buy == "Lapis Leggings" and coins > 700:
                    buy_confirm_lapis_leggings = input("Type Y / N to confirm order. Price: 700 coins")

                    if buy_confirm_lapis_leggings == "Y":
                        inventory.append("Lapis Leggings")
                        coins = coins - 700
                        print("You bought a pair of Lapis Leggings!")
                    else:
                        return
                
                if shop_buy == "Lapis Boots" and coins > 400:
                    buy_confirm_lapis_boots = input("Type Y / N to confirm order. Price: 400 coins")

                    if buy_confirm_lapis_boots == "Y":
                        inventory.append("Lapis Boots")
                        coins = coins - 400
                        print("You bought a pair of Lapis Boots!")
            
                    else:
                        return



            

    console()
    if console_command == "/q":
        console()
console_main()

while 1==1:
    console_main()
I get no errors, but the /s command I made doesn't do anything, and I guess you can run the code for yourself. If someone could tell me why this is happening, I would understand this logic structure a lot more. Thank you!
Reply
#2
At line 12 your location is set to ["base"] (a list). But to get into your shop, location must be "base" (a str). These things are not the same.
Reply
#3
Thanks! Frankly I'm a little ashamed I didn't see that :( I appreciate that though!
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Optimisation problem - star identification pberrett 1 2,252 Apr-01-2019, 12:17 AM
Last Post: scidam
  Symbol identification in variables Ollie 2 3,233 Apr-05-2017, 09:48 AM
Last Post: gullidog

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020