• News

• Industries

• Learning & Support

• Community

• Marketplace # Why does getting a number from an array cause it to get several at a time?

I am trying to set up an array for a “Hint” system in a puzzle game. What I did was set up an integer array that contains the number of pieces in the puzzle. I set the default to zero, and when the hint button is pressed, it adds 1 to the obtained hint number. I tested this to see if it was outputting the numbers in order (as it should), and the print string was giving me several different numbers at a time, and out of sequence. Any idea what I have done wrong here? Are you sure this blueprint is what you want? Currently it’s doing HintNumber = Hints[HintNumber]+1, which makes no sense to me.

The hint number is the stored variable for the hint’s number. Each number (in the case of this puzzle, there are 52 pieces) is linking to a button on a grid. Depending on the what number the “hint number” is, determines which button on the puzzle will be revealed (by changing its color and tag).

The game is a Picross type of game where you have a ten by ten grid, with numbers in each column and row. To beat the puzzle, you have to determine what the pattern on the grid is (using the numbers in the columns and rows).

And I don’t know if this is the correct set up for what I am trying to do or not. If there is a better way to set this up, I would appreciate the advice.

I still don’t understand. What’s exactly is a hint number? Is it the index of the revealed tile, or the index of the hint itself? You seem to be using it as both.

As I can see, you are always adding 1 to the value of Hints[Hint Number] to Hint Number, which is working as your array index.

Lets say that you have this values as defaults:

Hints array
Index 0 - 10
Index 1 - 4
Index 2 - 6
Index 3 - 1

When you find the HintNumber = 2, your function does this:

Set HintNumber = Hint + 1
Set HintNumber = 6 + 1
Set HintNumber = 7

Is that what you are looking for?

What I understood from the situation you’ve described and is not working for you, you should want something like this: This way, you will increment the value of the corresponding index from HintNumber.

The hint number is the stored value of the index. As it turned out, the problem was in the logic for what to do upon each number being found. I ended up removing the array entirely, setting the default value of the hint number to zero, and adding one every time the “hint” button is clicked. I initially had wanted to just find a random number, which is why I was trying the array, but I figured out I can do the randomization in the logic function (so the puzzle isn’t answered in order by hitting the hint button). Thanks for the advice, though.