Coin save data

Get help using Construct 2

Post » Sun Aug 11, 2013 4:41 am

Didn't think this would be so difficult..

Each of my game's levels has coins you can collect. I want to save which coins are collected to a dictionary so they don't re-spawn when you die or load the game.

I got it somewhat working by looping through the coins at the start and giving them an ID, saving the ID of the coins collected to a dictionary, then looping through the dictionary and destroying the coins with the same ID. It was something like that at least -w-;

Problem is I've got a bunch of different levels so I have to factor that in, else Coin #1 you collected in 1-1 will also be destroyed in 1-2 and so on. I attempted this but it ended in a mess of loops and substrings and str/int conversion and so on. Ugh.

Any ideas?MadFactory2013-08-11 13:50:00
Image
B
234
S
27
G
13
Posts: 1,784
Reputation: 18,274

Post » Sun Aug 11, 2013 7:13 am

Hi @MadFactory,

I often use invisible sprites as spawn points, not sure if this is the method you are using?

If it is, perhaps you could add an instance variable to each spawn sprite. Then once a particular coin has been collected, update the instance var for its corresponding spawn point and save it. When you come to respawn a level, only spawn coins at spawn points where instance var is = ?.

Jeez, I've never used the word spawn so many times in a message ;)

Anyway, not sure if this will help, but it's one way you could do it!

Blacksmith2013-08-11 07:15:04
B
33
S
6
G
7
Posts: 494
Reputation: 8,252

Post » Sun Aug 11, 2013 1:50 pm

Bump
Image
B
234
S
27
G
13
Posts: 1,784
Reputation: 18,274

Post » Sun Aug 11, 2013 3:43 pm

B
38
S
16
G
17
Posts: 2,230
Reputation: 17,220

Post » Sun Aug 11, 2013 3:45 pm

Couldn't you just give the coins a boolean variable collected. Set it to true when collected.
I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775

Post » Sun Aug 11, 2013 4:41 pm

Thanks @Whiteclaws

I had to change it up a bit because I'm not using C2's layouts and UID's are constantly changing, but it really helped.

Here are the final events:

Image
B
234
S
27
G
13
Posts: 1,784
Reputation: 18,274

Post » Sun Aug 11, 2013 4:47 pm

Glad I helped !

I'm really excited to see what you are cooking us :)
B
38
S
16
G
17
Posts: 2,230
Reputation: 17,220

Post » Sun Aug 11, 2013 6:22 pm

use persist behavior to coins
B
103
S
25
G
40
Posts: 1,876
Reputation: 31,885


Return to How do I....?

Who is online

Users browsing this forum: bikachu, Exabot [Bot], GabrielBalas, LukeNecklace, SoldjahBoy, Zaksoid and 11 guests