How do i use arrays?

  • 1d array = a spreadsheet with just 1 column but however many rows you want

    a 2d array = a spreadsheet with 2 columns and however many rows.

    a 3d array = a spreadsheet with 3 columns and however many rows.

    1d is correct but 2d and 3d are more like this:

    a 2d array = a spreadsheet with however many columns and however many rows.

    a 3d array = a spreadsheet with however many columns and however many rows and however many pages.

  • gonna check out that tutorial ramones.

  • I have a vague understanding of arrays. Could someone help me understand how they work.

    Arrays are nothing more than more powerful variables. A single variable can only hold 1 thing. Arrays are variables that you can actually page though your data like a spread sheet.

    How about this example. Say you had 3 monsters in your game and needed to know what their health was, and how much magic they have for spells.

    Array.MonsterArray 2X3X1 makes an array that holds data for 6 things(2x3) forget the 1 for now.

                   Health   Magic   

    Monster1    10       3

    Monster2     4       6

    Monster3    10      10

    So you woulds need a MonsterArray 2,3 to hold the data. Then for example if you wanted to know how much magic monster2 had you would look for":

    Array.MonsterArray(1,1) and that would tell you it had 6 magic points.

    *note arrays start at zero and count up so the first element would be 0 the second 1 and the third 2

  • Guyon R0J0hound aridale

    the problem isn't in understanding array the manual understanding them so well even all tutorial do that but the problem how can i make them on construct2 this maybe the 5th time i have tried but still i lost :(

    see this level page

    http://dl.dropbox.com/u/67034121/forum/level%20page.capx

    i tried to made but i really get miss with it , i wanted the win button to make sprite 2nd frame, and if clicked on finished it finish the seleceted or the last unlocked frame and make it 3rd frame of levels object. you gonna say this can be done with variable but the problem isn't in this the problem that i wanna see it in easy example to try to do it in harder one like levels has 1-3 stars , worlds and sometimes special levels....

  • zsangerous Hope this helps: levelSelect.capx

  • ramones

    i can't see the file this error come:

    <img src="http://i50.tinypic.com/a14peg.jpg" border="0" />

  • There shouldn't be a - on the end of the filename.

  • ramones

    <img src="http://i49.tinypic.com/2nvatzl.jpg" border="0" />

    see the picture i downloaded your capx and another one from arcade examples and see your file looks something else with "-" can you re-save and re-upload it i think the problem from saving the files.

  • zsangerous

    *edit* fixed previous link

    (ah there was a space at the end of the link, it works in Firefox but Chrome inserts a '-')

  • zsangerous: You should also learn to rename files in your OS.

    Basic knowledge like this is required to make proper games. Know your tools !

  • ramones thanks this is a good example ^^ ill try to do more stuffs on it

    Kyatric i have just learned it ^^ http://www.mediacollege.com/microsoft/windows/extension-change.html

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Hey, sorry to necro this post, but I have a question. I'm new to C2 (and, more or less, to game making in general) and while I understand the basics of arrays, I wondered if Yann or someone else could elaborate on this:

    And also, I never set so much data by end. I always end up putting all that in a string and parsing it (via tokenat and tokencount)

    But that's another story (:

    Yann2012-05-22 18:34:31

    How do you accomplish this? I think my biggest "problem" with arrays is just setting up a large one requires so many actions which just seems tedious, but if there's a way I could just string them all together in one field and have the code sort it into coordinates for me, that would be super useful! (Assuming I'm understanding what you said)

  • Foxe92

    Yeah, you necroforophile.

    That's indeed a very old corpse you digged here. These days I tend to avoid such process. Because the string is usually tedious to make, so tedious to maintain and also the events to parse it are tedious to write. Not complex, but tedious.

    These days I just use my JSON plugin

    I find it clearer, easier to use and more versatile. Though I would still use the Array plugin for simple flat list and the Dictionary plugin for simple list of key-value pair.

    I use the JSON plugin when I want to load more complex datastructure and when I want to have something easy to read/maintain.

    For example I could have an array of monsters like this

    [ 
        {type:"orc", hp:50},
        {type:"demon", hp:100},
        {type:"slimy", hp:20},
        ...
    ][/code:17skam44] in a JSON and easily spawn them at random.
    
    Anyway, to answer your question, tokenat allows you to access a part of a string considering a specific character as a separator.
    For example, if you have a string like[code:17skam44]"apple, banana, pear, cherry"[/code:17skam44]if you do[code:17skam44]tokenat("apple, banana, pear, cherry", 2, ",")[/code:17skam44]You split the string into parts (tokens) using the coma as a separator, and you get the part of index 2 (counting from 0). So it returns "pear".[code:17skam44]0: "apple"
    1: "banana"
    2: "pear"
    3: "cherry[/code:17skam44]
    tokenCount on the other end gives you how many token you have in a string, using the given separtor[code:17skam44]tokenCount("apple, banana, pear, cherry", ",")[/code:17skam44]returns 4
    
    So using a clever loop you can easily fill an array[code:17skam44]-> Array: set size (0,1,1)
    + repeat tokenCount("apple, banana, pear, cherry", ",")
        -> Array: push tokenat("apple, banana, pear, cherry", loopindex, ",") to back[/code:17skam44]
  • Oh gosh, thanks! Such an awesome and thorough answer!

    I will take a look at your plugin and see if I can figure it out, but that token loop is a pretty clever little trick. I definitely never would have thought to do something like that, even if I'd been familiar with tokenat/count.

    Seriously, thanks a ton!

  • Really the trick for loop is cleaver. Nice to learn about tokencount and tokenat.

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