Array woes

Get help using Construct 2

Post » Thu Jun 02, 2016 8:46 pm

I'm having some really annoying issues with arrays. Maybe I'm just not understanding how they work on a fundamental level.

Image

I have an array like this one with some values filled in that pertain to characteristics of the the characters at the top. Things like age, gender, eye color etc. I set all this up at the start of the layout.

I want to be able to add NEW characters into the array but every time I try to do that the array gets really weird in the debug layout. For example if I try to insert another character named "Jim" on the x axis he'll be inserted at the front of the array no problem...but if I try to add the other values, gender and so on they'll be strewn throughout every corner of the array.

Everythings good.

Image

And then I insert new values...

Image

What the heck?

Also, by default an array has a 1 for depth, if I turn that to zero (because why the hell would I need zdepth in a 2d array, right?) this happens.

Image

Can anyone clue me in on what exactly it is that I'm doing wrong here? What am I not understanding?

Thanks for any help.
B
19
S
7
G
10
Posts: 82
Reputation: 4,996

Post » Thu Jun 02, 2016 8:57 pm

If you insert at 0, then that column is already there. Don't insert any more, just set the rest of the data at index 0.

C2 has it's own rules for arrays. Even if not used, the default size needs to be 1.
ImageImageImage
B
71
S
22
G
247
Posts: 3,756
Reputation: 137,558

Post » Thu Jun 02, 2016 9:54 pm

@blackhornet

Ohh, I think I see. So I'm inserting twice and that's basically shifting all of my values over twice? I still don't understand how the other characters are ending up with 3 values for gender though. Shouldn't that stay at 2 regardless?

That's a problem. Inserting values seemed ideal since I don't want to have to set values at specific indexes later in game. I want to be able to just "insert" a new row and column sort of dynamically and be done with it.
B
19
S
7
G
10
Posts: 82
Reputation: 4,996

Post » Thu Jun 02, 2016 9:59 pm

Think of it as inserting a column, then inserting a row - the array grows in both dimensions then.
ImageImageImage
B
71
S
22
G
247
Posts: 3,756
Reputation: 137,558

Post » Thu Jun 02, 2016 10:07 pm

@blackhornet

Okay, okay yeah that makes a lot of sense actually.

Thank you very much :)
B
19
S
7
G
10
Posts: 82
Reputation: 4,996

Post » Fri Jun 03, 2016 1:35 pm

If anyone can give me a tip though on how to add multiple values into an array without having to put them at specific indexes though it would be appreciated.

Like it would be nice to add someone's name and have all the associated data go along with it in that same column. Is that something that's even possible?
B
19
S
7
G
10
Posts: 82
Reputation: 4,996

Post » Fri Jun 03, 2016 1:48 pm

insert your info as a string............arr_npc>insert "jim"&","&"male" at index 0 on x axis and then retrieve it with tokenat
What I know would fill a Book , what I don't know would fill a Library
B
37
S
12
G
29
Posts: 331
Reputation: 16,499

Post » Sat Jun 04, 2016 1:56 pm

@granpa okay, I'll give that a shot. Thank you very much :)
B
19
S
7
G
10
Posts: 82
Reputation: 4,996


Return to How do I....?

Who is online

Users browsing this forum: Google [Bot] and 8 guests