Need assistance coding a hint system in blueprints

I am trying to set a hint system for a puzzle game. My game is a picross game with 100 squares per puzzle in a 10 by 10 grid. When solved, the grid will show an image. I have the game completely coded, but I would like to add a hint system. I have it working, but it isn’t ideal. Currently, my code generates a random number between 0 and the last index in each puzzle. Then, if the user presses the hint button, the square assigned to that random integer will reveal the answer for that square. However, if the square has already been filled in, nothing will show up, and the hint will be wasted.

I need a way to make it generate a new random integer if the square is already correct. I tried simply comparing the current state of said square and the solution, but all this did was make it generate the same number repeatedly. Anyone know how to fix this?

one ugly choice would be to have a recursive method search for an unused tile.
Another choice would be to have more data awareness using perhaps an array of filled in tiles, then using that array you can prune and hints that are no longer applicable.

I tried creating a function that runs on the event tick which checks my solution and compares it to each square’s current state. Then if each current state and solution are correct, it would fill a respective bool in an array. This function works properly, but when I add the data from the bool array to compare against the hints, it returns the same hint repeatedly.

Hi,

I partially understand your game but that is not going to stop me from offering a solution to your problem :wink:

Here are my suggestions:

  1. I think that the random number generators are ‘pseudo random’ so try different random number generators or fdiff ranges.
  2. Put the random number generator inside a loop and compare the value of the random number generated with the number of the square. Stop the loop when the random number generated is not the same as the number of the square.

Hope this helps

Here are screenshots of my current code.

The first image shows my code for the function that checks if each square is correct. This is attached to the event tick.

The second is attached to the button press for the hint. Each square in each puzzle that has a hint has a similar set up in this function.

A random number is generated at the start of each puzzle (on the begin play node), and assigned to the HintNum variable. (Note, is normally set to search between 0 and last index, but I have it set to 0 to 1 for testing).

In the hint code, it first finds which integer is set in the “HintNum” variable. For the sake of explanation, we will just say it is 0. The code then finds which puzzle is currently on screen, and gets the “tags” I have assigned for the solution, and compares it to the corresponding tag in a local array (which are filled in as the user plays the game. I.e. they click the color black on a square that should be black, the local tag is set to black). All tags at the start of the puzzle are defaulted to read “NULL.” So, if square 10 is supposed to be black, but is NULL, then the first two array elements are not equal. Thus if HintNum is 0 and the two tags are not equal, then they are filled in with the correct color/tag (black). This is what is happening on that second part of the code. If, however, the two tags ARE equal it will generate a new random integer, and repeat the process until it finds an incorrect square. At least, that is how it is supposed to work. It does not.

If you need further explanation, let me know.

I posted my current code set up above. I have it set to search for two array elements that are not currently equal each time the hint button is pressed, and fill it in. Just not sure my set up is correct or ideal. It only finds one square, no matter if I hit the button ten times.