Python Forum
[pygame] Inventory problems. Weapons equipped to wrong slot - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: Game Development (https://python-forum.io/forum-11.html)
+--- Thread: [pygame] Inventory problems. Weapons equipped to wrong slot (/thread-17954.html)



[pygame] Inventory problems. Weapons equipped to wrong slot - SheeppOSU - Apr-30-2019

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


RE: [pygame] Inventory problems. Weapons equipped to wrong slot - nilamo - Apr-30-2019

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



RE: [pygame] Inventory problems. Weapons equipped to wrong slot - SheeppOSU - Apr-30-2019

- 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


RE: [pygame] Inventory problems. Weapons equipped to wrong slot - nilamo - May-01-2019

Are we looking at the same file? Line 781 involves opening cabins, and 882 is about passwords.


RE: [pygame] Inventory problems. Weapons equipped to wrong slot - SheeppOSU - May-01-2019

Very sorry about that, it is now updated.


RE: [pygame] Inventory problems. Weapons equipped to wrong slot - SheeppOSU - May-04-2019

Just updated it again


RE: [pygame] Inventory problems. Weapons equipped to wrong slot - SheeppOSU - May-07-2019

Sorry if my code is messy or confusing