Hi. Nev here -

Want to set up an inventory system that lets you pick up items, move them and drop them somewhere else, like in Dark Cloud?
Well here's how -

First create an active object called 'slot'.
Every item that you can hold should be set to different directions and a empty slot animation in dir 0.
i.e. you can have up to 31 items. For extra items just move to a different animation.
Place several of these objects in a grid. It only works if you only have up to 10 'slot's per row and 10 columns, but you can have less.
Create a new object from one of these. This will be the object you are currently holding.

First we need to set up an id system, so that you can set individual items even though the objects are all the same.
This is the event to do it.

Start of Level -
"Slot" - Set Alterable Value A to ( X( "Slot" ) - A ) / D + ( C * ( Y( "Slot" ) - B ) / E )

Where A,B are the co-ordinates for the first "Slot" on the level,
C is the number of "Slot"s per row and D,E is the distances between their hotspots.

Eg. If each "Slot" was 32x32, their hotspots at 16,16 and they were placed in a 10x10 grid
(100 "Slot"s) next to each other with the first "Slot" at 32,32, the event would be,

Start of Level -
"Slot" - set Value A( "Slot" ) = ( X( "Slot" ) - 32 ) / 32 + ( 10 * ( Y( "Slot" ) - 32 ) / 32 )

This gives each "Slot" a unique ID based on their position.

Now you need to create and Ini object to store what each slot contains.
The ini should look like this -

[Items]
1=0
2=0
3=0
4=0
etc..

Next is an event to load what item each slot contains at the start of the level.

Start of Level -
"Slot" - Set Alterable Value B to groupitem( "Ini Plus", "Items", str$( Value A( "Slot" ) ) )

This loads the value of the "Slot" from the item for that "Slot" (Which is the string of the ID we set up before - each one is different)

N.B. You can use an ordinary "Ini" object to do this but it requires an extra event to set the "Ini"s group and item, and you have to use a new event

for everything you load because of this.
I use a "Ini Plus" for its 'groupitem' so you can load multiple items in the same event.

Now you need an event to show the item in the "Slot"

Always -
"Slot" - Set direction to Value B( "Slot" )

This completes the "Slot" Setup. Now we move onto manipulating the items.
You can create a new event group if you want.

Basically whats going to happen is that when you click on a "Slot", the "Cursor"s Value A is set to the "Slot"s Value B, the "Slot"s Value B is set

to what ever the "Cursor"s Value A used to be and the "Cursor" becomes visible. But we can't do this directly. Why? Look below -

A -> B The Value of B is set to A's value
B -> A A's value is set to B's value.
A == B But wait, we just set B's value to A's, so now both A and B have A's value.
B's value has been erased.
In order to not overwrite B's value we need to have an intermediate event.
B -> C
A -> B
C -> A This way B's value is temporary held in C so it isn't overwritten by A.

The events to do this are as follows -

"Slot": Internal flag 0 is off
+ User clicks with left button on "Slot" -
"Slot" - Set internal flag 0 on
"Cursor" - Set Alterable Value B to Value A( "Cursor" )
Set Alterable Value A to Value B( "Slot" )
Set internal flag 0 on

"Slot": Internal flag 0 is on -
"Slot" - Set internal flag 0 off
Set Alterable Value B to Value B( "Cursor" )

Lastly are a few events to setup the "Cursor" -

"Cursor": Internal flag 0 is off -
"Cursor" - Set Alterable Value B to 0
Set Position at (-64,-64) (off screen - change the co-ordinates if "Cursor" is still on the screen)

"Cursor": Internal flag 0 is on -
"Cursor" - Set direction to Value A( "Cursor" )
Set X Position to XMouse
Set Y Position to YMouse

Alterable Value A of "Cursor" = 0 -
"Cursor" - Set internal flag 0 off

There - Your inventory system is almost complete. Now we only need a couple of events to save the items in each slot.

Start of Level -
"Cursor" - Set Value C to 1

Value A "Slot" = Value C "Cursor" -
"Cursor" - Add 1 to Alterable Value C
"Ini Plus" ("Ini") - Set Group to "Items"
Set item to str$( Value C( "Cursor" )
Set value to Value B( "Slot" )

Value C "Cursor" > (# of "slot") -
"Cursor" - Set Value C to 1

Now the inventory system is finished. You can now move your items to different locations in your inventory.
I'll let you add events to pick up, use and drop items.

Until the next article -
- Nev out.