How to make inventory without arrays.

  • 9 favourites

Attached Files

The following files have been attached to this tutorial:

.capx

Stats

1,792 visits, 3,255 views

Translations

This tutorial hasn't been translated.

Tools

Hello! In this tutorial i will show you how to make an inventory.

Layout

First thing you need to do is to make 2 sprites:

- Item_Slot - Should be 16, 32, 64 (...).

- Item (dropped) - You can make a sword or something.

Make 2 new animations in both sprites. In Item it should be another item and in Item_Slot you need to make animations that shows your Item.

In the end, rename the Item_Slot animations to ID_0, ID_1, ID_2 and in Item ID_1, ID_2.

Variables

For Item_Slot make 3 variables:

- Item_Id - should be 0 on start. This variable holds the item ID in it.

- Slot_id - it's unique id for your slot, first make 4 slots, it will be growing number (1st one Slot_id = 1, 2nd Slot_id = 2 (...) )

- Locked - it should be 0 on start. This variable shows if the slot is locked ( = 1) or not ( =0)

Before we go to the Event Sheet, add Mouse object.

Event Sheet

Add event where:

- When LMB clicked on 'Item'

- Slot.Slot_Id = 1 (1 is for the first slot)

- Slot.Locked = 0

Do:

Slot|Set Slot.Item_Id to Item.id

Slot|Set animation to "ID_" &item.id

Item|Destroy

Slot|Set Slot.Locked to 1

Do the same for every slot you have, the only thing you need to change is Sprite.Id_Slot = (every slot id)

So, if you have 4 slots, copy event 4 times and in first, change Slot_id to 1;2;3;4.

Item debugging

In this engine, there is an bug. If 2 items overlapp themselves and player press them, only 1 item gets into the slot.

This is how i solved it:

When:

- Item is overlapping Item

Do:

Item|Move at angle > Pixels 2 > Angle random(0,360)

It should debug itself quickly.

Dropping

In top-down game, you need to create character sprite.

When:

- RMB clicked on Slot

- Slot.Locked = 1

Do:

Slot|Set animation to "ID_0"

Character| Spawn an object "Item"

Item|Set ID to Slot.Item_ID

Item|Set animation to "ID_" &Slot.Item_ID

Slot|Set Slot.Item_ID to "0"

Slot|Set Slot.Locked to 0

.CAPX

eqexample.capx

Download now 179.8 KB
  • 0 Comments

  • Order by
Want to leave a comment? Login or Register an account!