Python Forum
[pygame] Inventory items not working
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[pygame] Inventory items not working
#3
Im not saying this is the cause of your issue. But it illustrates the problem of people helping you.

Quote:
    def drawWeap(self, i):
        gearBool = i.itemReturn()
        if self.direct == 'Left':
            if gearBool['armor'] == None:
                self.character = gD.blit(Character[3], (self.x, self.y))
            if gearBool['armor'] != None:
                self.character = gD.blit(Character[3], (self.x, self.y))
                self.armor = gD.blit(self.color[3], (self.x, self.y))
            if gearBool['weapon'] != None:
                self.weapon = gD.blit(self.weapType[3], (self.x - round(self.width*.8), self.y + round(self.height/2)))

This entire drawWeap() function is massively redundant. First of all there should be if and elif, not only if. Secondly you should split the logic of armor and weapons from the draw method. This alone would reduce the number of lines in your code as well make your code much more readable to new people looking at it. If you copy and paste a lot of code, then you are doing something wrong. And you are doing that.

Another example:
Sure of course it works, but it makes it a nightmare to help fix bugs. As an example...when i look at this i dont know if your issue is a draw issue or a logic issue. You do not use docstrings. You do not use modules. You are not using the builtin pygame rects (You should never have to do self.x/self.y in pygame with rects). You are using time.sleep (Which is always bad in GUI).

Im sure if i wanted to devote the time i could make your 1200 line code into 300~ lines. But i dont have the time or patience. Reducing it by that much would make it much more easy to work on. Less bugs. Easier to find bugs that do come along.

My suggestion would be to rework your code better. If your asking yourself "how do i do that?". I would read (or reread) the series of tutorials and follow along through part 1 through part 8. If you do that you should be thinking your code is in bad shape. And you would know tips on how to fix it. By doing all that more people would be willing to help. No one is ever going to look through thousands of lines of code, devote time in understanding your spaghetti code...without at least pay.

If you want to look at a good structure of RPG in python/pygame, check out Mekire's RPG Cabbages and kings. Check out how loading sprites are separated into a tools module. check out the player module. You never have redundant code, he labels every single method on what it does, each method does ONE thing.

EDIT:
Another suggestion is dont make us wait. Get us straight to the problem. Dont make use type username/passwords in. Dont make us kill the first guy. Put us straight at the shop. Programmers always have cheat arguments in development to progress users to the point of the problem....eliminating the need to start at the beginning.
Recommended Tutorials:
Reply


Messages In This Thread
[pygame] Inventory items not working - by SheeppOSU - May-12-2019, 12:36 AM
RE: [pygame] Inventory items not working - by metulburr - May-22-2019, 10:39 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Adding an inventory and a combat system to a text based adventure game detkitten 2 6,980 Dec-17-2019, 03:40 AM
Last Post: detkitten
  [pygame] Inventory problems. Weapons equipped to wrong slot SheeppOSU 6 4,113 May-07-2019, 02:46 AM
Last Post: SheeppOSU
  [pygame] Blitting armor and weapons with inventory SheeppOSU 3 2,952 Apr-29-2019, 02:31 AM
Last Post: SheeppOSU
  [pygame] Equiping inventory slots with invisible buttons SheeppOSU 6 4,832 Apr-26-2019, 08:45 PM
Last Post: SheeppOSU
  [pyGame] Key Event not Working !... JamieVanCadsand 7 20,870 Sep-29-2017, 08:59 PM
Last Post: Mekire

Forum Jump:

User Panel Messages

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