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

0 favourites
  • 12 posts
From the Asset Store
Game with complete Source-Code (Construct 3 / .c3p) + HTML5 Exported.
  • 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:

    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.

    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?

  • 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.

  • 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. goo.gl/giWv8S

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • This may be easier than my capx:

  • You are including the space character. Use: trim(tokenat(Anagrams,wordCount,","))

  • 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.

  • 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.

  • 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.

  • A key-value pair is actually what you have. The key is the 'word', the value is 1=guessed, 0=not-guessed.

  • 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:

    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

  • Y=0 is your words. Your first column (indexed at 0) is all of the words. Your flag is in the second column (indexed at 1).

    For consistency/clarity, change your original code from Set value X to Set value XY. The expression would now be:

    X=wordCount

    Y=0

    Value=trim(tokenat(Anagrams,wordCount,","))

    That will make it more obvious that the words are ending up in column (Y) =0.

  • Good morning and thanks! This has been wonderful in clarifying how these objects work -- and my simple ideas are finally working! ... much appreciation

    ... and so much more to learn ...

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