which is the best way to make an inventory

Get help using Construct 2

Post » Wed Mar 12, 2014 10:16 pm

My question it's ¿which is the best way to make an inventory? specifically in a Rol-game

Thanks for answer

PD:// I'm Sorry by my english
B
3
Posts: 2
Reputation: 179

Post » Thu Mar 13, 2014 12:02 am

For inventories arrays are the way to go.

A 1D array should be enaugh. If your inventory has 100 slots, then the width of the array would be also 100. If the character picks up one item it's ID will be stored in the first emtpy array.

Then you have to make a array-"for each element" for drawing all the items, if the user opens the inventory.
B
10
S
2
Posts: 135
Reputation: 1,090

Post » Thu Mar 13, 2014 12:42 am

Thanks for all !! :D
Now I know how I'll do
B
3
Posts: 2
Reputation: 179

Post » Thu Mar 13, 2014 1:43 am

No Problem. :)
B
10
S
2
Posts: 135
Reputation: 1,090

Post » Thu Mar 13, 2014 10:51 am

I'm gonna asking here because is related with this.

In the game i'm developing i'm thinking in have also a store so buy some products, which the best way so save this ?
Because i gonna have a lot of diferents images with diferences prices, and diferent values.
I'm thinking use instance variables, but in this case i have to create 1 sprite to each image, to each text with value and shopping cart.

Here is a example of my store with 2 products:

Image
thanks
B
11
S
3
Posts: 39
Reputation: 814

Post » Thu Mar 13, 2014 1:45 pm

I'd use 1 sprite object and put each image item in the object frames, then create a "price" instance variable for the object for each item, create one text object (which is set to the object "price" (copy the text object so there is multiple objects of the same instance) set each text object instance variable to the name of the item you wish the price value to hold. Do check on which frame item is selected and then add/deduct price value from the relates text value. Hope that makes sense, try looking at my Zelda tutorial, it may help you.

https://www.scirra.com/tutorials/670/ze ... e-easy-way
B
14
S
6
G
3
Posts: 83
Reputation: 4,238

Post » Thu Mar 13, 2014 5:30 pm

Thanks ;) Help me a lot.
Now i have 1 dictionary with this:
Name-Quantity
Food-3
Drink-2

1 food object (with 2 frames, 2 clones) - instance variables: name, price, foodanimation
1 text object (2 clones) - instance variables: name

Seems good ?
Now i have a problem, i want enable/disable drag drop behavior according have or not this item on inventory, for that i make a for each key over dictionay, and compare the key with the instance variables of food object , but all food object turn disable :S
B
11
S
3
Posts: 39
Reputation: 814

Post » Fri Mar 14, 2014 12:51 pm

can someone help me ?
B
11
S
3
Posts: 39
Reputation: 814

Post » Fri Mar 14, 2014 1:07 pm

I would simply use a 2D array.

The X row contains all the item information: price (X0), Infotext (X1), satiety (X2), etc.

The Y row stands for each individual item.

Example:

.........X0..........................X1...............................................X2

Y0......5............."This is a cool Item"..................................5

Y1....14,99......"This is an even cooler Item"...................10

Y2.....20......."This is the item you ever wanted".............15


You than make a "for each Y element" array-loop, for creating the sprites and text. Set their sprite to array.CurY (this is the Y position of each item in the array and simultaneously the ID).

You only need 1 sprite object (with all frames for all items) and 1 text object for all items.


Edit:

For the drag & drop I would do something like this:

If object is overlapping the background of the shop menu
- on key press: activate drag & drop behaviour

- on key release: deactivate drag & drop behaviour
B
10
S
2
Posts: 135
Reputation: 1,090

Post » Fri Mar 14, 2014 1:40 pm

I've not done a drag and drop feature before, so not sure, maybe post a screen shot of the code?
B
14
S
6
G
3
Posts: 83
Reputation: 4,238

Next

Return to How do I....?

Who is online

Users browsing this forum: No registered users and 6 guests