inventory slot reading freezing game ticks
I made a function to read the contents of the agents inventory but when it has items in its inventory the function freezes the game ticks and the only fix is to restart the world
def get_inventory_information():
# Initialize an empty list for the inventory
inventory = []
# Loop over each slot in the inventory
for i in range(27):
# Get the item name and count for the current slot
item_name = agent.get_item_detail(i)
item_count = agent.get_item_count(i)
# Create a dictionary for the current slot
inventory_slot = {'item_name': item_name, 'item_count': item_count}
# Add the current slot to the inventory
inventory.append(inventory_slot)
# Return the completed inventory
return inventory
def on_on_inventory():
inventory = get_inventory_information()
inventorysay = ""
for i in inventory:
inventorysay += "Item: " + i['item_name'] + ", Count: " + str(i['item_count']) + " "
inventorysay += "Item: " + i['item_name'] + ", Count: " + str(i['item_count']) + " "
player.say(inventorysay)
1
-
Hey Tomas,
Sorry for the wait. A member of our team made some modifications to your code.
"it does take a couple seconds to run through every slot in the agent's inventory, but it's not a long wait"def get_inventory_information(): # Initialize an empty list for the inventory inventory = [] # Loop over each slot in the inventory # Pro-tip: i counts from 0 to 26, but the agent's inventory slots are 1 to 27, hence i+1 in the code below for i in range(27): # Get the item name and count for the current slot. item_name = agent.get_item(i+1).id if not item_name == "air": item_count = agent.get_item_count(i+1) item_slot = i+1 # Create a dictionary for the current slot inventory_slot = {'item_name': item_name, 'item_count': item_count, 'item_slot': item_slot} inventory.append(inventory_slot) # Return the completed inventory return inventory def on_player_message(message, sender, receiver, message_type): if message == "inventory": inventory = get_inventory_information() inventorysay = "\n" for i in inventory: inventorysay += "Slot: " + str(i.get('item_slot')) + ", Item: " + i.get('item_name') + ", Count: " + str(i.get('item_count')) + "\n" player.say(inventorysay)
1 -
Thank you.
can you tell me why it freezesd the game ticks. Was it the reading of item_slot = 0 ?
I didn't see any any documentation on " def on_player_message(message, sender, receiver, message_type): " can you link to the documentation for it. :)1
Please sign in to leave a comment.
Comments
2 comments