Skip to content
This repository has been archived by the owner on Oct 2, 2019. It is now read-only.

Ability to access inventory #33

Open
fredyvilla opened this issue Jan 29, 2016 · 8 comments
Open

Ability to access inventory #33

fredyvilla opened this issue Jan 29, 2016 · 8 comments
Labels

Comments

@fredyvilla
Copy link

Issue by fredyvilla
Wednesday Jan 13, 2016 at 04:47 GMT
Originally opened as fredyvilla#6


Give the bot the ability to store its inventory in the atomspace. Use spock to receive an event when a new inventory item is added.

@akhisud
Copy link

akhisud commented Feb 2, 2016

The 'inventory' plugin has event listeners that listen to events that occur when windows are opened or closed, and that triggers some callback function. However, the window that shows inventory and hot bar won't open every time the bot picks up something and it gets added to the inventory. Hence, I can't really find an event for simple inventory update in spockbot, that I can get spockControlPlugin to listen to. Help on this?

@Gjum
Copy link

Gjum commented Feb 2, 2016

Technically, the inventory (including hotbar and armor etc.) is always open. For what you are doing, you might want to look at the inventory_set_slot event.

Picking up items works like this: the bot is near an item, then the server decides that the bot picks it up, kills the item entity and sends a set_slot to the bot. SpockBot handles this, updates the internal inventory state correctly, and emits inventory_set_slot. Keep in mind though that this event gets also emitted for other reasons than picking up items.

@akhisud
Copy link

akhisud commented Feb 3, 2016

So basically, I'm going to listen for the 'set_slot' event in the SpockControl.py plugin and convert the incoming data (which will have a window_id, slot_nr and slot_data) into a msg. I'll then publish this msg on to a topic and the node that subscribes to this topic can update the incoming inventory to atomspace.
However, I don't know what format this 'slot_data' will be in, so I'm not able to write a msg format for it. I can't test this either cos the bot doesn't have functionality to pick up inventory right now. Do I use some other approach?

@akhisud
Copy link

akhisud commented Feb 3, 2016

Oh, also I'm going to check if the window_id of the incoming data is INV_WINID_PLAYER (the inventory plugin sets this to -1, representing player's inventory window), then I'll be sure that something has been picked up and that's why the event set_slot has occured. Does that cover cases?

@Gjum
Copy link

Gjum commented Feb 3, 2016

You can pick up items when any window is open, so checking INV_WINID_PLAYER is unnecessary and wrong.

It also looks like this project is using an old and incomplete inventory plugin (https://github.com/opencog/opencog-to-minecraft/blob/master/spockextras/inventory.py), please use the official one, it's python2 compatible now.

@akhisud
Copy link

akhisud commented Feb 3, 2016

Thanks! Also, could you briefly explain INV_SLOT_NR_CURSOR and INV_WINID_CURSOR?

@Gjum
Copy link

Gjum commented Feb 3, 2016

When you click a slot to pick it up, it follows your mouse as you move it around. that is modeled as a separate slot, the "cursor slot" inventory.cursor_slot. When joining a server, it is empty by default.
The constants you mentioned are what the server sends when updating the cursor slot, and every slot update requires the slot's nr and window ID. As the cursor slot is special, it always has nr and window ID set to -1.

Btw, thanks for helping me to find out what we need docs for 😉

@akhisud
Copy link

akhisud commented Feb 4, 2016

Thanks! In the messenger plugin's, setMessage() function:

def setMessage(self, msg, data):

    for key in data:
        if hasattr(msg, key):
            if isinstance(data[key], dict):
                pass
            elif isinstance(data[key], list):
                pass
            else:
                setattr(msg, key, data[key])

If the data[key] is a list or dict, it just sets the corresponding msg value to an empty list or dict. However, the .msg file I am looking to create, does have a list in it. How can this be handled?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

3 participants