saving data characters

Get help using Construct 2

Post » Thu Jul 11, 2013 2:35 am

Friends. Good night.

I have a doubt. I'm building a tower defense that in place of the towers will be characters.

They will have attributes (attack strength, speed, stamina and defense), I can create a family for everyone to have that data.

My doubt is how safe these information.

I thought about using array, but it does not accept strings. And the dictionary, from what I understand, that would be a dictionary for each character / tower.

This is the way? There are other means.

Example of what I have to save.

Name / attack strength / speed / stamina / defense
pc1 /   1             / 2    / 1      / 3
pc2 /   3             / 1    / 3      / 2
pc3 /   2             / 3    / 2      / 4
B
37
S
8
G
4
Posts: 85
Reputation: 5,099

Post » Thu Jul 11, 2013 2:57 am

But arrays do store strings...? I have used them several times for exactly this. But now that you can just save the game state, I prefer to just use variables on arrays. This works totally fine unless you are doing something like a CCG which requires in-depth information, like how many times an attack has had a modifier increase.

EDIT: I should clarify that I prefer variables on arrays, then creating an instance of that array when a character is created and linking it to them (set instance variable 'id' to character 'uid'). It's a better method than storing the variables directly on the character for a number of reasons, like if the character gets destroyed but comes back later or you find you do want to store some info in an array later down the track, or maybe you want to store the data of each character for a debriefing layout.Tobye2013-07-11 03:22:45
B
28
S
8
G
5
Posts: 429
Reputation: 6,977

Post » Thu Jul 11, 2013 3:28 am

Sorry friend, but I could not quite understand your method. Is there any example or any tutorial for esclerecer did this?

Thank you for your attention.
B
37
S
8
G
4
Posts: 85
Reputation: 5,099

Post » Thu Jul 11, 2013 3:59 am

Hm, no I haven't seen any. I learnt all this stuff myself and don't have any demos ready. But I will try to explain it:

1. Create an array in the editor. Add an instance variable to it for each value you wish to store (attack, defence, etc.)

2. On start of the game, destroy array (just to keep it clean)

3. Condition 'on character created' > create object 'array'. Set value of array's instance variable 'id' (which you also include when creating the variables for the array) to 'character.uid'. Then set all other variables to the desired values.

4. Whenever something affects 'character', pick the corresponding array by adding the condition 'array.id = character.uid'. Now alter the values of the array's variables asthough it was the character.


This is a very simple way to do things that still allows more flexibility than storing the values directly on the character. If you think that you will need more control over the information, then yes also use the array's cells.

I don't have time to fully explain my methods for that right now sorry, but essentially you just use 'push' to add a string value (say 'attack') on the X axis, then values on the Y axis (starting from 1, because 0 will be your string). Then you can do things like run loops for 'array.height' times, using local variables as counters to get the value for each cell under a string: array.At(array.indexOf("attack"),counter))

That method is actually quite easy to use, just there is a lot of possibility so deciding the right ways of indexing and retrieving the information for your game will likely take some time and thought. Hope that helps!

EDIT: Also in case you haven't noticed, I'm not a fan of using a single array for all the characters. I really can't see any reason to do it that way and many reasons why not to. So unless you have a very specific reason for doing so (and if you do I'd like to know why out of curiosity :) ), the main thing I suggest is to store values for each character in their own object.Tobye2013-07-11 04:24:56
B
28
S
8
G
5
Posts: 429
Reputation: 6,977


Return to How do I....?

Who is online

Users browsing this forum: Evanetot, Pulstar, wowsoundsg, Yahoo [Bot] and 4 guests