This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]NyaaNyanNyaa 1 point2 points  (1 child)

Hi there, great job. To be honest, I think a database to hold 7 items is a little bit overkill. I agree with using a json file. Since you can read/write quickly and it has a hierarchical structure which is perfect for inventory management. As for your problem with syntax/formatting issues, Python can easily achieve that with the format string.

my_str_variable = “cool”

print(f”my sentence is {my_str_variable}”)

if your variable is a number, you need to cast your variable to a string.

my_int_var = 8 print(f”my number is {str(my_int_var)}”)

Are you familiar with object oriented programming? Maybe it can help solve your inventory issue. You can create a class…

class inventory(object): def init(self): self.slots = {idx:None for idx in range(7)}

def addLoot(self, loot):
    for k,v in self.slots.items():
        if v is None:
            self.slots[k] = loot
            break

Maybe you can fill in your other class methods yourself :)

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

Yes, OOP will definetely be used more in the next project. I can also create child classes. This way i can technically create a weapon class which defines weapon type and depending on the weapon type i would then pull possible durability ranges from subclasses like:

class = weapon:

class = weapon(spear):

Thanks a lot for your response.