Item Persistence

0 favourites
  • 6 posts
From the Asset Store
Over 1700 16x16 pixel art RPG icons for item and skills
  • Hi guys, I've been wracking my brain over this for a while now, my issue is that I want to have an easy-to-use system for storing the status of each chest in a given layout (whether it has been opened or not, and have it act accordingly).

    As it stands I have all of the chests inside a family, and the family has an instance variable called "opened" which can be either 1 or 0. The rest of the setup would be easier explained with a screenshot:

    <img src="http://img204.imageshack.us/img204/3814/a55ce1a54d5a4248adffe67.png" border="0" />

    I'd rather not have to do this using global variables if it means I'll need a variable for each chest since the game will have a large number of chests.

    Can anybody help me brainstorm how I would do this? I'm totally stuck!

  • It seems that for now the only way I can do it is to have a unique object for each chest and just manually copy the events/actions and change the objects the events/actions reference.

  • I had to do something similar for Minitroid using instance variables and hash tables. Say you have 10 gems that, once picked up, never return. You want to give them an instance variable called ID and set them to 1,2,3,4, and so on for each gem. Then you make a hashtable with 10 keys - also 1,2,3,4, and so on.

    When a gem is picked up, check if the key with the same ID has a value of 0 - if so, destroy the gem and set the key value to 1.

    Now, when the level is loaded, loop through the keys and see if any of the values are 1. If so, destroy the gem with that ID.

    Alternatively you can just check if the key exists.

    Make sense? Probably not. I suck at explaining these things. I can whip up an example .capx if needed :)

    EDIT: Sorry, I keep forgetting hashtables are called dictionaries in C2. I will never get used to that -.-

  • You can make the common code for the chest, and when opening the chest, it call another code (or eventsheet).

    Inside the called code, you can make anything you want, like making exclusive rewards or random stuffs.

    -------------------------------------

    Also, it may help

    https://dl.dropbox.com/u/47035927/Samples/IDs/monster_spawn.capx

    https://dl.dropbox.com/u/47035927/Samples/IDs/index.html

    Also, this read can help a lot:

    http://www.scirra.com/tutorials/361/understanding-uid-iid-health-cards-and-rocket-smoke-trail

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Thanks to both of you, Tokinsom you gave me a totally different angle which worked a treat, and TELLES0808 you gave me a neat idea for randomising the loot :)

  • It's been a few days and I have a workable system in place now that I wanted to share.

    Here is the schedule for when the player opens a chest:

    <img src="http://img801.imageshack.us/img801/4153/8e3c8f9f849a415080d2947.png" border="0" />

    The chest has a instance variable called "Chest_ID" which is unique for each chest (in this case, it is the chest in Buster's house). When the chest is opened the schedule sets a webstorage key with the same name as the Chest_ID and sets its value to "opened". Keep in mind that this example is using session storage rather than local, this is just for testing purposes to allow me to easily reset all the values without having to wipe my browser cache, it will be set to local in the final version)

    And this is the schedule that runs at the start of the layout to check what chests have been opened:

    <img src="http://img163.imageshack.us/img163/8006/5380b0561ed34797bbad538.png" border="0" />

    So, when the layout begins it checks the relevant webstorage key for Chest_ID "BH_1" and if it set to "opened" it will run the chest opening actions.

    It isn't the most efficient way of doing things, but it allows me to determine what loot each chest contains, which is what I want.

    I hope this is useful, and if anyone can see a way I could make this more efficient please let me know!

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