Skip to main content

inventory slot reading freezing game ticks

Comments

2 comments

  • Ernie Support
    Support

    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
  • tomas reid

    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.