Legacy GM Slot Rotating inventory?

O

Orvais

Guest
Hello!

I'm a bit new to game maker but I've made some decent progress as I've worked on my game, but I hit a bit a brick wall. I was looking inventory systems and found a tutorial from Shaun Spalding which showed the basics on how to make a working inventory system.

What I'm trying to achieve is when I pick up an item, and when you press right or left. it'll shift the whole inventory in that one direction. I made a mock a mock up of what I was trying to achieve.





The large square in the middle is the item that is highlighted at the time when I want to select something.

I'm not exactly sure on how to pull this off, and I've gotten a bit desperate so I made an account to seek some help.

Is there a way to shift every items slot to the next one over to mimic this effect?

Here's the code I'm using from shaun through his guide.
Code:
//Create invent
/*
Inventory Items
0 = Sword
1 = Red Potion
2 = Blue Potion
3 = Yellow Key
*/

globalvar showInv; //Display the inventory?
showInv = true;
globalvar maxItems; //total item slots
maxItems = 5;

for (i = 0; i < maxItems; i += 1)
{
    global.inventory[i] = -1;
}
Code:
//Draw Event
if (showInv)
{
    var x1,x2,y1,y2;
    x1 = view_xview[0];
    x2 = x1 + view_wview[0];
    y1 = view_yview[0];
    y2 = y1 + 64;

    draw_set_color(c_black);
    draw_set_alpha(0.8);
    draw_rectangle(x1,y1,x2,y2,0);
    draw_set_alpha(1);
   
    for (i = 0; i < maxItems; i += 1)
    {
        draw_sprite(spr_border,0,x1+24+(i * 40),y2-24)
        if (global.inventory[i] != -1)
        {
            draw_sprite(spr_items,global.inventory[i],x1+24+(i * 40),y2-24)
        }
    }
}
Code:
//Check Event

for (i = 0; i < maxItems; i += 1)
{
    if (global.inventory[i] == argument0) //if slot "i" contains argument 0
    {
        return(1);
    }
}
return(0);
unsure if I need to post anything else to aid me here.
 
J

JealousOfCrows

Guest
To make the inventory you want I would break the problem into chunks and discuss them a little more in 'pseudo code'. Shaun's code doesn't do this so I suggest ditching it. Take what you have learned from it though. It is also a good idea to show what your code currently does to make it easier to understand what needs modification.

There are multiple methods to achieve something like the gif you have posted above. Also if memory serves me right, you are missing a key script from Shaun's code. Right now your just drawing the inventory and checking if it has something in it.
 
G

gloomytoad

Guest
Gain an advanced understanding of Arrays. YouTube for how Arrays work in memory (Not a gamemaker tutorial).
Once you establish this understanding start looking into the ds_list data structure in gamemaker.
ONCE AGAIN do not youtube a gamemaker tutorial on Lists as they will not explain to you what they are.

It is after this understanding that you can then implement your own inventory system.
I cannot post a link as this is a new account but I am a Computer Science major with 12 years experience in Gamemaker. My channel is dedicated to educating Gamemaker users of actual Computer Science concepts in Gamemaker as most information out there is....

A variable stores information:
health = 100;

When in reality, under the surface.. Health is stored as a double which can consume 32 bits in memory. Computer memory is organized in 1 Byte partitions which are 8 bits. So an "int", but really a double as gamemaker stores all numbers, consumes 4 bytes of memory (in binary) that represent the number 100 while "health" references the address where this information is found in memory.

If learning things like this sounds intriguing you can sub my YoutTube channel GloomyToad
A better understanding of what your code is doing in memory and how it is processed will help you code better and have a much better understanding!

With all of this being said, I will be creating a more in depth inventory example with every step explained very soon.
 
Last edited by a moderator:
O

Orvais

Guest
Gain an advanced understanding of Arrays. YouTube for how Arrays work in memory (Not a gamemaker tutorial).
Once you establish this understanding start looking into the ds_list data structure in gamemaker.
ONCE AGAIN do not youtube a gamemaker tutorial on Lists as they will not explain to you what they are.

It is after this understanding that you can then implement your own inventory system.
I cannot post a link as this is a new account but I am a Computer Science major with 12 years experience in Gamemaker. My channel is dedicated to educating Gamemaker users of actual Computer Science concepts in Gamemaker as most information out there is....

A variable stores information:
health = 100;

When in reality, under the surface.. Health is stored as a double which can consume 32 bits in memory. Computer memory is organized in 1 Byte partitions which are 8 bits. So an "int", but really a double as gamemaker stores all numbers, consumes 4 bytes of memory (in binary) that represent the number 100 while "health" references the address where this information is found in memory.

If learning things like this sounds intriguing you can sub my YoutTube channel GloomyToad
A better understanding of what your code is doing in memory and how it is processed will help you code better and have a much better understanding!

With all of this being said, I will be creating a more in depth inventory example with every step explained very soon.
I appreciate that advice, I'll try and give these a more in depth look.
 
G

gloomytoad

Guest
I appreciate that advice, I'll try and give these a more in depth look.
Follow my playlist. I just released 2 videos on arrays as well as releasing a video on Memory in a computer that you can start at.
Currently am uploading video 3 on arrays that gives you an introduction on inventory, then in the description there will be a link to a full inventory system
using some of these concepts.
 
Top