Page 2 of 2

Re: Inventory system

PostPosted: Mon Oct 29, 2012 7:40 am
by skydereign
What do you mean not move? The item actor has three events, movement taken care of in the mouse button down event. When you add an item to your inventory, it moves it sets its position. When you click an item in the inventory, it starts to follow the mouse. If you have the three events, it should work like it does in the demo.

Re: Inventory system

PostPosted: Mon Oct 29, 2012 10:44 am
by MrJolteon
It worked when I added
Code: Select all
inv_clear();

in a Create Actor-event in view.
Now to move the inventory...

Re: Inventory system

PostPosted: Mon Oct 29, 2012 7:04 pm
by MrJolteon
One more question,
After I moved the inventory, when I pick up multiple items, they will be moved to exactly the same location.
Image
How do I fix it?
Here's my global code, and I can provide a ged if needed.
Code: Select all
#define MAX_INV 9
int inv[MAX_INV] = {0};
int cur_item = -1;
int cur_type = -1;

void
inv_clear ()
{
    int i;
 
    for(i=0;i<MAX_INV;i++)
    {
        inv[i]=-1;
    }
}

#define ITEM_CREATE 0
#define ITEM_MOVE 1

int
inv_add (int type, int action)
{
    int i;
 
    for(i=0;i<MAX_INV;i++)
    {
        if(inv[i]==-1) // empty
        {
            inv[i] = type;
            cur_type = type;
            switch(action)
            {
                case ITEM_CREATE:
                CreateActor("item", "ricon", "view", "(none)",
                        view.width/2-60+(i%3)*60, view.height*2/3+i/3*60, true)->inv_pos = i;
                break;
 
                case ITEM_MOVE:
                ChangeParent("Event Actor", "view");
                xscreen = view.width-400;
                yscreen = view.height-115;
                inv_pos = i;
                break;
            }
            cur_type = -1;
            return 1;
        }
    }
    return 0;
}

void
inv_remove (int idx)
{
    inv[idx] = -1;
}

Re: Inventory system

PostPosted: Mon Oct 29, 2012 9:11 pm
by skydereign
First thing is that your CreateActor function in the inv_add function is still using the division and modulus which should create them in multiple rows. The reason for them all being placed in the same spot is that your ITEM_MOVE case in the same function places them all in the same spot. You need to keep the reference to i, which allows them to be offset by i. If you don't know what I mean, just take a look at the code I posted, same lines as I mentioned in my previous post.

Re: Inventory system

PostPosted: Mon Oct 29, 2012 9:18 pm
by MrJolteon
I see, thanks.

Re: Inventory system

PostPosted: Tue Oct 30, 2012 6:15 am
by MrJolteon
Am I supposed to do this?
Code: Select all
            switch(action)
            {
                case ITEM_CREATE:
                CreateActor("item", "ricon", "view", "(none)",
                        view.width-400+i, view.height-115, true)->inv_pos = i; //<===
                break;
 
                case ITEM_MOVE:
                ChangeParent("Event Actor", "view");
                xscreen = view.width-400+i; //<===
                yscreen = view.height-115; //<===
                inv_pos = i;
                break;
            }

Re: Inventory system

PostPosted: Tue Oct 30, 2012 6:21 am
by skydereign
Let's think about that. The only change is that you add i to the x coordinate. What is i? That variable stands for the position in the array that the item is placed. It varies from values 0-8 in your code. So, is adding one pixel enough to keep your items separated? I highly doubt it, which is why in the original code it used i*60, making the x offset 60 instead of 1.

Re: Inventory system

PostPosted: Tue Oct 30, 2012 9:04 am
by MrJolteon
Oh. Thanks.

Re: Inventory system

PostPosted: Sun Feb 03, 2013 11:37 am
by MrJolteon
This might seem like a stupid question, but how do I add more usable items?

Re: Inventory system

PostPosted: Sun Feb 03, 2013 7:18 pm
by skydereign
Items are a little weird in this system. But, the actor variable that distinguishes different items is type (which are really just different animations). In the item's create actor, it sets type equal to animindex if the actor doesn't have a creator. So, just add more animations to the item's actor to create more items, and add the mouse button down events to the locations the item needs to activate, and you should be set. You could set up some #defines for each animindex, so it is a little clearer in the item use locations (for instance trigger's mouse button down event).