Item Persistence

Get help using Construct 2

Post » Tue Sep 11, 2012 11:38 am

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:


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!
slap it onto the flappy bird template...
bang it on google play with all the other shovelware...
sorted...
B
36
S
7
G
4
Posts: 322
Reputation: 8,170

Post » Tue Sep 11, 2012 12:29 pm

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.
slap it onto the flappy bird template...
bang it on google play with all the other shovelware...
sorted...
B
36
S
7
G
4
Posts: 322
Reputation: 8,170

Post » Tue Sep 11, 2012 2:38 pm

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 -.-Tokinsom2012-09-11 18:29:04
Image
B
225
S
27
G
13
Posts: 1,774
Reputation: 18,024

Post » Tue Sep 11, 2012 5:07 pm

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-trailTELLES08082012-09-11 17:09:25
ImageImageImageImageImageImage
B
92
S
19
G
12
Posts: 1,190
Reputation: 18,272

Post » Wed Sep 12, 2012 11:07 am

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 :)
slap it onto the flappy bird template...
bang it on google play with all the other shovelware...
sorted...
B
36
S
7
G
4
Posts: 322
Reputation: 8,170

Post » Sun Sep 16, 2012 1:34 pm

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:


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:

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!
slap it onto the flappy bird template...
bang it on google play with all the other shovelware...
sorted...
B
36
S
7
G
4
Posts: 322
Reputation: 8,170


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 17 guests