Inventory system

Non-platform specific questions.

Re: Inventory system

Postby skydereign » Mon Oct 29, 2012 7:40 am

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.
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Re: Inventory system

Postby MrJolteon » Mon Oct 29, 2012 10:44 am

It worked when I added
Code: Select all
inv_clear();

in a Create Actor-event in view.
Now to move the inventory...
Join us on Discord!
Game Editor 2
These are the best ways to reach me these days


Your local Community Janitor, always lurking in the shadows...
User avatar
MrJolteon
 
Posts: 2326
Joined: Sat Aug 09, 2008 3:25 pm
Location: Stranded under endless sky
Score: 105 Give a positive score

Re: Inventory system

Postby MrJolteon » Mon Oct 29, 2012 7:04 pm

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;
}
Join us on Discord!
Game Editor 2
These are the best ways to reach me these days


Your local Community Janitor, always lurking in the shadows...
User avatar
MrJolteon
 
Posts: 2326
Joined: Sat Aug 09, 2008 3:25 pm
Location: Stranded under endless sky
Score: 105 Give a positive score

Re: Inventory system

Postby skydereign » Mon Oct 29, 2012 9:11 pm

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.
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Re: Inventory system

Postby MrJolteon » Mon Oct 29, 2012 9:18 pm

I see, thanks.
Join us on Discord!
Game Editor 2
These are the best ways to reach me these days


Your local Community Janitor, always lurking in the shadows...
User avatar
MrJolteon
 
Posts: 2326
Joined: Sat Aug 09, 2008 3:25 pm
Location: Stranded under endless sky
Score: 105 Give a positive score

Re: Inventory system

Postby MrJolteon » Tue Oct 30, 2012 6:15 am

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;
            }
Join us on Discord!
Game Editor 2
These are the best ways to reach me these days


Your local Community Janitor, always lurking in the shadows...
User avatar
MrJolteon
 
Posts: 2326
Joined: Sat Aug 09, 2008 3:25 pm
Location: Stranded under endless sky
Score: 105 Give a positive score

Re: Inventory system

Postby skydereign » Tue Oct 30, 2012 6:21 am

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.
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Re: Inventory system

Postby MrJolteon » Tue Oct 30, 2012 9:04 am

Oh. Thanks.
Join us on Discord!
Game Editor 2
These are the best ways to reach me these days


Your local Community Janitor, always lurking in the shadows...
User avatar
MrJolteon
 
Posts: 2326
Joined: Sat Aug 09, 2008 3:25 pm
Location: Stranded under endless sky
Score: 105 Give a positive score

Re: Inventory system

Postby MrJolteon » Sun Feb 03, 2013 11:37 am

This might seem like a stupid question, but how do I add more usable items?
Join us on Discord!
Game Editor 2
These are the best ways to reach me these days


Your local Community Janitor, always lurking in the shadows...
User avatar
MrJolteon
 
Posts: 2326
Joined: Sat Aug 09, 2008 3:25 pm
Location: Stranded under endless sky
Score: 105 Give a positive score

Re: Inventory system

Postby skydereign » Sun Feb 03, 2013 7:18 pm

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).
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Previous

Return to General

Who is online

Users browsing this forum: No registered users and 1 guest

cron