Managing multiple arrays. RPG Inventory help?

Get help using Construct 2

Post » Wed Feb 05, 2014 6:13 am

Howdy Scirra forums. I've used the search function and I've seen some examples. I'm requesting someone basically walk through what I need to do in C2. If C2 were a scripting language, I think I could handle this. But well, C2 isn't a scripting language. I'm still new to WYSIWYG game editors.

I'll try to explain what I need help with to the best of my abilities.

Theory
I'd have three arrays for what I need to accomplish.

1] The first array would be a 1 dimensional array for inventory "slots".
[0][1][2][3][4][5][6][7][8][9][10]...


Each address would have a value.
0 = empty, 1=Item.animation frame 1, 2=Item.animation frame 3=Item.animation frame 3,etc . . . .

2] The second array would also be 1 dimensional. For equipped items.
[0]Feet
[1]Body
[2]R_arm
[3]L_arm
[4]Head
[6]Weapon
[7]Trinket1
[8]Trinket2

Each address would have a value.
0 = empty, 1=Item.animation frame 1, 2=Item.animation frame 3=Item.animation frame 3,etc . . . .

3] The third array would connect the two arrays and contain all the info for items. It'd be multi dimensional.

[0] Animation frame to show
[0a] Item Name
[0b] STR to add
[0c] DEF to add
[0d] INT to add
[0e] LCK to add
[0f] CON to add
[0g] MP to add
[0h] Hp to add

The action would work like this:
o Player kills monster
o Computer does a random number roll.
o If the number roll is a success, the monster spawns a random item
o When the player collides("picks up") the item, the items corresponding number is added to the Slot array.

There'd be a menu that shows the inventory with each item number having a specific animation frame that would show in the inventory. Then you'd be able to drag from the slots into the equip. The slot address would become 0, and the Equip Inventory would gain the previous address.

Then, the third array would run the calculation and add whatever specific stats to the player's stats.
_________________________________________________


Does the basic game theory for what I want to achieve make sense? Is there a simpler way to implement what I want to add?
B
12
S
3
G
2
Posts: 110
Reputation: 2,435

Post » Wed Feb 05, 2014 9:59 am

Bump
B
12
S
3
G
2
Posts: 110
Reputation: 2,435

Post » Wed Feb 05, 2014 10:33 am

Hey there.

Your basic game workflow should work.
I have a concern though. The third array is more like a database than a dynamic array. I would suggest using the CSV plugin to do that, so you could access the datas with something more clear to read (column names is realy nice when you have lots of data for each items, plus it's easier to check/complete/modify item stats through Excel).

Now let's take a look through your actions :
o Player kills monster > call function "handle loot", passing monster.UID as parameter, before destruction of the monster object
o Computer does a random number roll. > handled by the function
o If the number roll is a success, the monster spawns a random item > handled by the function. spawn an item on the monster coordinates.
o When the player collides("picks up") the item, the items corresponding number is added to the Slot array.
> Player On collision with Item, call function "pick up item" passing item.UID as parameter.

The pick up function would first look for the first empty slot, then if it found one store the item in it, destroy the item object from the game. You should have a function that would update the "slot" display on the screen to call here.

Then, you'll need a new "item object" (let's call it item2), different from the first one as it will be in your inventory, and would have a drag-drop behavior.
item2 on drop on equipSlot : if the equip slot isn't empty, handle the unequipment of the object first. Then, update the EquipSlot with the caracteristics of the new item. Last, remove item from inventory/destroy the item2 object.

I tried to described a little more what would be the script-flow, hope it helps.
B
17
S
8
G
4
Posts: 461
Reputation: 6,157

Post » Wed Feb 05, 2014 11:05 am

inventory basic example

i created a basic demo of some of the things you will need, and how you can use the array, i would use only one array, the itemlist, the rest is only states, and you get the info always from itemlist

from there you can random generate, give information, whatever you like
using x array for the list and y for properties
ImageImage
B
70
S
21
G
7
Posts: 827
Reputation: 10,052

Post » Wed Feb 05, 2014 11:57 am

Thanks guys!
B
12
S
3
G
2
Posts: 110
Reputation: 2,435


Return to How do I....?

Who is online

Users browsing this forum: tarek2 and 28 guests