Python Forum
[pygame] Inventory problems. Weapons equipped to wrong slot
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[pygame] Inventory problems. Weapons equipped to wrong slot
#1
I've been working on this inventory for so long. i finally made big progress on it but I have a problem.

Problem - When buying an item it is successfully put into inventory. The only problem is that it takes the original weapon. The original weapon is still there but does nothing when being equipped. Instead, the new weapon takes equips the original weapon.

I have my code in github here - https://github.com/Sheepposu/Destination - It can also be installed and tested for visual purposes. All the pictures should be updated into the picture folder. TIA for your help
Reply
#2
Quote:
    def equipChange(self, receive, equips=None, n=None):
        if receive:
            return self.equips
        elif not receive:
            if n in self.availableSlots:
                equipsList = list(equips)
                if Counter(equipsList).most_common(1) == [(n, 2)]:
                    equipsList.remove(n)
                equipsTuple = tuple(equipsList)
                equ = 0
                equ2 = 0
                for eq in equipsTuple:
                    equ += eq
                for eq2 in self.equips:
                    equ2 += eq2
                if equ != equ2:
                    self.equips = equips
                else:
                    equipsList = list(equipsTuple)
                    equipsList.remove(n)
                    equipsTuple = tuple(equipsList)
                    self.equips = equipsTuple
        time.sleep(.5)

Help me to help you:
- what does receive mean?
- what's equips, and how is it different from self.equips?
- what's the equipsList for?
- what does this mean?
            equ = 0
            equ2 = 0
            for eq in equipsTuple:
                equ += eq
            for eq2 in self.equips:
                equ2 += eq2
            if equ != equ2:
                self.equips = equips
Reply
#3
- If receive is true it will send self.equips (It is to be received)
- equips is the self.equips with the new equip
- I was having problems when creating the new equip, I don't remember all the details but, I had to turn it into a list, remove something, and then retuple it.
- That was something about deciding, did they click the same slot, did they click a different slot, if they clicked the same slot it would do something that messed up the inventory and so I added that to fix it.

Also sorry, let me point out the lines responsible for this part of the code. Starting on line 781 is the inventory class. giveItem starts on line 882, and openShop starts on line 756
Reply
#4
Are we looking at the same file? Line 781 involves opening cabins, and 882 is about passwords.
Reply
#5
Very sorry about that, it is now updated.
Reply
#6
Just updated it again
Reply
#7
Sorry if my code is messy or confusing
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  pygame installation problems Gheryk 5 8,499 Nov-29-2023, 08:49 PM
Last Post: E_Mohamed
  [PyGame] Problems with jump code in pygame Joningstone 4 5,272 Aug-23-2021, 08:23 PM
Last Post: deanhystad
  Adding an inventory and a combat system to a text based adventure game detkitten 2 6,809 Dec-17-2019, 03:40 AM
Last Post: detkitten
  [pygame] Inventory items not working SheeppOSU 14 6,617 May-27-2019, 09:44 PM
Last Post: metulburr
  [Pygame] Problems with my textbox SheeppOSU 1 3,038 May-27-2019, 12:03 AM
Last Post: metulburr
  [pygame] Blitting armor and weapons with inventory SheeppOSU 3 2,858 Apr-29-2019, 02:31 AM
Last Post: SheeppOSU
  [pygame] Equiping inventory slots with invisible buttons SheeppOSU 6 4,660 Apr-26-2019, 08:45 PM
Last Post: SheeppOSU
  drawing, moving, and collision problems (pygame) SheeppOSU 26 14,443 Apr-22-2019, 03:09 AM
Last Post: SheeppOSU
  Problems with loading buttons (pygame) SheeppOSU 2 3,056 Apr-12-2019, 08:04 PM
Last Post: SheeppOSU

Forum Jump:

User Panel Messages

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