How do I use families for RPG items?

Get help using Construct 2

Post » Thu Feb 19, 2015 4:13 am

I was hoping someone more familiar with C2 and Javascript could check my thinking and give me some suggestions. I am currently using sprites to represent and hold all my RPG items. I'm not sure if this is the best choice, but it seems like a good idea for now. I have another sprite that I am using as an Itemslot, which so far can hold an Item and stores it's UID. My first problem is that items disappear between layouts, which leaves the Itemslot holding a UID for a nonexistent Item. I was thinking that I should maybe have each nonempty Itemslot store it's item as JSON and destroy it when the layout ends, and restore it on the start of the next layout. Is this a good solution or is there a better one?

My other question is about callbacks. I would like to assign functions to the Item family, such as onEquip, onUnequip, and onUse, so that armor can boost the character's armor stat in onEquip or a weapon can spawn a bunch of bullets in onUse. I guess I am looking for family members to share polymorphism. Would it be better to implement this with an RPGItem behavior or plugin?
B
14
S
5
G
1
Posts: 189
Reputation: 1,536

Post » Thu Feb 19, 2015 8:05 am

It may be enough to just add the "Persistent" Behavior to the sprite so it retains its properties when you change layouts and come back.

I try to do as much as possible without plugins so I am safe if it is discontinued or not working after an update anymore.
You could try to use instance Variables. Something like Strenght, Life, Armor, IsEquipped and each item has different values for it. And then you can check if "IsEquipped" is 1/true you take the other variables and add them to your player stats. So leather armor has Armor of 1, Plate armor has a value of 3 for example. And this would then be added to the character stats. Do you know what I mean?
B
51
S
15
G
5
Posts: 681
Reputation: 8,399

Post » Thu Feb 19, 2015 10:20 pm

The Persist behavior only preserves stuff if you come back to the same layout. I'm looking for a way to let some items be persistent, but items in my inventory will follow me into a different layout.

As for plugins: I won't have any trouble with discontinued or poorly maintained plugins/behaviors if I am the one writing the plugins ;-B I couldn't find anything to suggest that families are polymorphic with respect to functions, but I just got my item behavior up and running. I have two items, and pushing a key triggers whatever item is in a particular slot, and then each item does it's own thing. It's just a little glue really. This way, at some point down the line I can very easily do crazy stuff like a cursed sword that sets you on fire when you pick it up, or enemies that can be placed in inventory slots.

I'm still having trouble keeping stuff between layouts. I noticed that even though itemslots are global and positioned on a global layer, they get reset every time a new layout starts. What is the best way to fix this?
B
14
S
5
G
1
Posts: 189
Reputation: 1,536

Post » Fri Feb 20, 2015 12:04 am

Youll probably want to use web storage / local storage to store the ID's of the items, then on layout start load the items in based on the ID's in the local storage variables. this has the added benefit of storing the items between sessions even if you completely close the game.
Made Cosmochoria - www.cosmochoria.com
Currently working on Slayaway Camp - www.slayawaycamp.com
B
25
S
7
G
3
Posts: 375
Reputation: 4,847

Post » Sat Feb 21, 2015 5:33 am

Thanks for your help, I'll check that out. I guess I have to get my behaviors to use JSON properly...
B
14
S
5
G
1
Posts: 189
Reputation: 1,536


Return to How do I....?