How do I use families for RPG items?

0 favourites
  • 5 posts
From the Asset Store
A collection of various zombie characters sprites for creating a 2D platformer or sidescroller game
  • 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?

  • 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?

  • 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?

  • 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.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Thanks for your help, I'll check that out. I guess I have to get my behaviors to use JSON properly...

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)