What am I missing? Please help with values in 2D Arrays.

Just started using Construct 2? Post your questions here

Post » Mon Jun 30, 2014 11:04 pm

I have successfully loaded a 2D Array with words into C2. I am having the hardest time just working with the array data. I have spent most of the day in tuts and forums on this, and feel this must be something easy I'm just not getting:

The array has a string value (the word) for X, and a numeric value(0) (number of times guessed) for Y

You can see a portion of my array in this shot from the debugger:
Image

However, if I try to call even something like ArrayWords.IndexOf("ES") (just to test for position a known word in the array), it always shows -1.
Image

The same is true even if I try a new 'Array Contains' condition for "ES". However, the manuals seem to indicate this is how it's done. What am I missing?
B
11
S
2
Posts: 86
Reputation: 1,001

Post » Mon Jun 30, 2014 11:51 pm

Can you post a capx that demonstrates the issue? I'm not sure what you're missing as it looks like it should work from what you've shown. See the capx attached and compare it to yours.
You do not have the required permissions to view the files attached to this post.
B
24
S
9
G
4
Posts: 1,646
Reputation: 6,596

Post » Tue Jul 01, 2014 12:28 am

Message: kbtbc can only post plain text URLS until they have 500 rep. 1 URLS modified. Why?
Thanks. Here is my capx ... a lot of stuff is toggled out because it's not working as I would expect.

Basically, for my education, I've modified the ghost shooter tut game to have a few random letters appear and am looking to build matches when you shoot them in the right order. I was able to get his working just by using find() and comparing against a string, but Arrays seem like a much better fit, but I am lost as to why it's so difficult or what is wrong with what I am trying.

I'll take a closer look at what you posted, too. http://goo.gl/giWv8S
Last edited by kbtbc on Tue Jul 01, 2014 12:56 am, edited 1 time in total.
B
11
S
2
Posts: 86
Reputation: 1,001

Post » Tue Jul 01, 2014 12:41 am

This may be easier than my capx:
Image
Image
B
11
S
2
Posts: 86
Reputation: 1,001

Post » Tue Jul 01, 2014 1:14 am

You are including the space character. Use: trim(tokenat(Anagrams,wordCount,","))
ImageImageImage
B
71
S
21
G
232
Posts: 3,695
Reputation: 129,866

Post » Tue Jul 01, 2014 1:18 am

Why don't you Set size to (tokencount( Anagrams, ","), 2, 1) instead of Set size to (1, 2, 1) in event 1? You don't even need that, if you use push. Also a Dictionary might be closer to what you need.
B
24
S
9
G
4
Posts: 1,646
Reputation: 6,596

Post » Tue Jul 01, 2014 2:01 am

Blackhornet, thanks! -- I knew it was something simple that I was overlooking.

Codah, Good idea on the size setting. (one reason for the format I have is that I plan to load the data from different letter sets, which might be different lengths, but the same logic could be applied. The reason I want to use the array instead of dictionary is that I also want to keep try whether a word has been guessed or not, and thus the Y field. Since a dictionary only contains key=value pairs, I thought an array would be better. Obviously, I'm still learning about a lot of this... (like how push works)... Could you elaborate a bit on why a Dictionary might be closer to my needs? That would help my understanding of learning how to choose best between these two storage objects.
B
11
S
2
Posts: 86
Reputation: 1,001

Post » Tue Jul 01, 2014 2:19 am

kbtbc wrote:Could you elaborate a bit on why a Dictionary might be closer to my needs? That would help my understanding of learning how to choose best between these two storage objects.


Well, I haven't analysed your code too much (unlike @BlackHornet :) ) but a dictionary stores a text/number pair, and that's what you're doing.. Take it with a grain of salt.
B
24
S
9
G
4
Posts: 1,646
Reputation: 6,596

Post » Tue Jul 01, 2014 2:33 am

A key-value pair is actually what you have. The key is the 'word', the value is 1=guessed, 0=not-guessed.
ImageImageImage
B
71
S
21
G
232
Posts: 3,695
Reputation: 129,866

Post » Tue Jul 01, 2014 3:29 am

Cool. I'll try both to help me learning -- you guys have already been great

.... meanwhile, back on the Arrays, I'm trying to read and update the Y value for correct matches.

It's still confusing me, Compare at XY -- (I'm looking for the Y value where the found word is) ... this is what I came up with, but doesn't work... I'm still searching for help. Here is what I tried, that doesn't work:

Image

EDIT: I think I got it ... The ValueAt for Y should be '1' ... and not '0' ... (but I thought indexes started at '0'?) ... shew my head is full
B
11
S
2
Posts: 86
Reputation: 1,001

Next

Return to Beginner's Questions

Who is online

Users browsing this forum: No registered users and 0 guests