Merge pull request #3628 from feyrkh/main

Fix incorrect example code in equipment tutorial
This commit is contained in:
Griatch 2024-10-08 21:51:14 +02:00 committed by GitHub
commit 3c64f61f17
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -402,18 +402,19 @@ class EquipmentHandler:
to_backpack = [obj] to_backpack = [obj]
else: else:
# for others (body, head), just replace whatever's there # for others (body, head), just replace whatever's there
replaced = [obj] to_backpack = [slots[use_slot]]
slots[use_slot] = obj slots[use_slot] = obj
for to_backpack_obj in to_backpack: for to_backpack_obj in to_backpack:
# put stuff in backpack # put stuff in backpack
slots[use_slot].append(to_backpack_obj) if to_backpack_obj:
slots[WieldLocation.BACKPACK].append(to_backpack_obj)
# store new state # store new state
self._save() self._save()
``` ```
Here we remember that every `EvAdventureObject` has an `inventory_use_slot` property that tells us where it goes. So we just need to move the object to that slot, replacing whatever is in that place from before. Anything we replace goes back to the backpack. Here we remember that every `EvAdventureObject` has an `inventory_use_slot` property that tells us where it goes. So we just need to move the object to that slot, replacing whatever is in that place from before. Anything we replace goes back to the backpack, as long as it's actually an item and not `None`, in the case where we are moving an item into an empty slot.
## Get everything ## Get everything