How do i use arrays?

Get help using Construct 2

Post » Sat May 26, 2012 9:04 pm

@zsangerous Hope this helps: levelSelect.capx

ramones2012-05-27 00:41:00
B
54
S
28
G
18
Posts: 1,520
Reputation: 25,020

Post » Sat May 26, 2012 10:04 pm

@ramones
i can't see the file this error come:


B
48
S
15
G
6
Posts: 795
Reputation: 12,035

Post » Sat May 26, 2012 11:58 pm

There shouldn't be a - on the end of the filename.
B
54
S
28
G
18
Posts: 1,520
Reputation: 25,020

Post » Sun May 27, 2012 12:14 am

@ramones

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.
B
48
S
15
G
6
Posts: 795
Reputation: 12,035

Post » Sun May 27, 2012 12:34 am

@zsangerous
*edit* fixed previous link

(ah there was a space at the end of the link, it works in Firefox but Chrome inserts a '-')ramones2012-05-27 00:41:43
B
54
S
28
G
18
Posts: 1,520
Reputation: 25,020

Post » Sun May 27, 2012 3:48 am

@zsangerous: You should also learn to rename files in your OS.
Basic knowledge like this is required to make proper games. Know your tools !
New to Construct ? Where to start

Image Image
Image Image

Please attach a capx to any help request or bug report !
Moderator
B
247
S
85
G
40
Posts: 7,000
Reputation: 57,795

Post » Sun May 27, 2012 5:53 am

@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
B
48
S
15
G
6
Posts: 795
Reputation: 12,035

Post » Sun May 25, 2014 12:36 pm

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:

Yann wrote: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)
B
4
Posts: 3
Reputation: 211

Post » Mon May 26, 2014 2:30 pm

@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 :D
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
Code: Select all
[
    {type:"orc", hp:50},
    {type:"demon", hp:100},
    {type:"slimy", hp:20},
    ...
]
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: Select all
"apple, banana, pear, cherry"
if you do
Code: Select all
tokenat("apple, banana, pear, cherry", 2, ",")
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: Select all
0: "apple"
1: "banana"
2: "pear"
3: "cherry

tokenCount on the other end gives you how many token you have in a string, using the given separtor
Code: Select all
tokenCount("apple, banana, pear, cherry", ",")
returns 4

So using a clever loop you can easily fill an array
Code: Select all
-> Array: set size (0,1,1)
+ repeat tokenCount("apple, banana, pear, cherry", ",")
    -> Array: push tokenat("apple, banana, pear, cherry", loopindex, ",") to back
B
60
S
22
G
14
Posts: 1,479
Reputation: 16,346

Post » Tue May 27, 2014 1:16 am

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!
B
4
Posts: 3
Reputation: 211

PreviousNext

Return to How do I....?

Who is online

Users browsing this forum: Donald Cela, Kagubro and 27 guests