Storing & using characters with their specs linked to it

0 favourites
  • 7 posts
From the Asset Store
A collection of various soldier character sprites for creating a 2D platformer or sidescroller game
  • Hey guys, didn't find a better description for the subject.

    Maybe this is a easy question for Construct users who have experience with storing data

    What I would like to do is the following:

    I have 28 characters (names) and 12 possible 'specs' (words).

    Each character has 4 of these possible 'specs'.

    I would like to use these 2 data rows in both ways:

    • getting every spec of a character
    • getting every character sharing the same spec.

    How can I do this in the most efficient way?

    I presume I have to use an array? What are the events look like for both functions?

    If someone can put me on the right track with some advice, I could find the rest.

    Thanks in advance!

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • What are these characters and specs? If they are they just bits of text data, you can store them in an array or a dictionary.

    With dictionary you can have the character as key name and put all specs into a comma separated string.

    So you'll have:

    Keyname="Character1", data="spec1,spec2,spec3,spec4"

    Use "For each key" loop and expressions like find() and tokenat() to search for/parse specs.

    Or you can make a 2D array, X axis will store character name, Y1-Y4 will store specs.

    Use array events like "For each element" and "Compare current value"/"Compare at XY" to search for a character/spec.

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

    In case these characters and specs are actual objects (like sprites), you can define an instance variable on the Spec sprite - "CharacterUID". This will allow to link characters with specs.

    To pick specs for a character:

    Spec compare instance variable -> CharacterUID=Character.UID

    To pick character for a spec:

    Character pick by Unique ID -> Spec.CharacterUID

  • Thank you so much for the 2 tips!

    I was trying out the way with the array but using dicitionary seems more logic for this one!

    (I didn't know we could use CSV in it)

  • Both arrays and dictionaries have their pros and cons. What's to choose depends on your data and how are you going to use it.

    There's actually a plugin that can help parsing CSV files or even convert them to arrays:

  • Hey I've tried a lot but I can't seem to find a way to write a event using the array for this function:

    The Array is orderd as following:

    X = Name1, Name2, Name3

    Y1= Spec1, Spec2, Spec 3

    Y2 = Spec 4, Spec5, Spec6

    Function:

    Textobject1 chooses randomly one of the three name. (that's no problem afcourse)

    In 2 instances of the same textobject2 I want to display the specs that are listed under the name that has been chosen and displayed in the first textobject1 (using a small loop for textobject2)

    If there is a golden event tip for this one, it would save a headache!

  • First, your array structure should be like this:

    X0,Y0 =Name1 (this element can also be referred as X0)

    X0,Y1 = Spec1

    X0,Y2 = Spec2

    X0,Y3 = Spec3

    X1,Y0 =Name2 (this element can also be referred as X1)

    X1,Y1 = Spec4

    X1,Y2 = Spec5

    X1,Y3 = Spec6

    To pick random name use this code:

    variable r=int(random(array.width))

    Text1 set text to "Name: " & array.at(r)

    To loop through all specs for this name:

    For y=0 to (array.height-1) -> Text2 append text array.at(r, loopindex) & " "

  • It worked!! wauw!

    Thank you so much Stan.

    In a couple of months, we're maybe going to need a man like you for bigger questions.

    I've seen your post about working with you as a freelancer, since we've some money for a freelancer for our project, I'll keep in touch!

    greetz and thank you

    Lennert

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