Save/Load Enemies

Get help using Construct 2

Post » Sun Mar 17, 2013 8:32 am

I like the idea of using an array, but I've never used them before, so bare with me.

Here is what I did (and maybe you can tell me what I'm doing wrong):

When an enemy is killed, I'm using the following event:

Enemies > On Destroyed
_____________-Array > Set Value at Enemies.ID(instanced variable) to 1


On the save button, I'm using:

Webstorage > Set Local Key "Array" to Array.AsJSON

On load:

Array > Load > JSON string "Array"

When the layout start, I created a subevent:

Array > Value of Enemies.ID = 1
For Each Enemies
____________- Destroy Enemies


The other thing is that I want all enemies to respawn when you leave the level and go back into the level, so I added a "Array > Clear" event for that, but it doesn't seem to be working either.

Thanks!
B
22
S
3
Posts: 451
Reputation: 2,135

Post » Sun Mar 17, 2013 10:54 am

Take a look at this .capx to see how it's done: http://www.scirra.com/forum/saving-and-loading-an-array-to-webstorage-capx_topic50970_post353466.html#353466Xavier2013-03-17 10:54:38
B
63
S
23
G
17
Posts: 254
Reputation: 14,342

Post » Sun Mar 17, 2013 11:14 am

Well just in case I made you this capx:

https://dl.dropbox.com/u/1910765/enemysave.capx

You should be able to modify it to your needs.
B
63
S
23
G
17
Posts: 254
Reputation: 14,342

Post » Sun Mar 17, 2013 5:48 pm

Hey Xavier,

For some reason the CLEAR button doesn't seem to actually set the array to all 0's Is this a bug in C2, or does it not do that?

B
22
S
3
Posts: 451
Reputation: 2,135

Post » Sun Mar 17, 2013 6:21 pm

UPDATE:

Got it working. My issue was trying to load "Array" instead of WebStorage.LocalValue("Array").

Thanks Xavier and Vee!
B
22
S
3
Posts: 451
Reputation: 2,135

Previous

Return to How do I....?

Who is online

Users browsing this forum: BinaryPanda, MarkThomas and 18 guests