Hi all.
Been at this a while.
simple Hide & seek game. did it in pascal in 1998, C++ 2011.
Now trying to make it 3d in UE5.4.1
I have my data table with hiding place’s, room floor and object where they are hiding. Empty field of used ( cat is hiding here) ,and cat name. which is filled when the place is randomly chosen.
Have a structure of hiding place made. 9 places for now. for setting up.
I get the table of row names, randomise it. for each loop of the 5 names of the cats.
Trouble I am having, is once I find a place, i want to mark it as used and put in the cat name. So when looking for the next cat hiding place it is not chosen again. 5 cats 5 hiding places.
But in Set members in S_Where_cat_is hidden i set the cats name and true to Used.
But same place can be chosen.
What I am doing wrong. and thanks in advanced.
If you pick a random item in an array every time then yes there is a chance you get the same location multiple times. There are multiple problems to look at seperately.
-
You should instead shuffle the hiding place array. When you then do a for loop over the hiding places, you will get all of the hiding places in random order.
-
A datatable can not be modified at runtime. A datatable is used to read data from, not to write data to.
-
“set members in struct” usage is incorrect here. It can not be used on a datatable entry, but you also need to keep in mind if you are attempting to modify a copy or a reference. In blueprint a copy is a round dot on the node pin, a reference I think is a square. If you modify a reference, the “set member…” node will actually modify the struct you give it. If you modify a copy, you are not modifying the original data but a copy.
I think the easiest solution would be:
- Make a shuffled copy (array) of hiding places.
- Ensure you have as many cats as hiding places (equal array length).
- Do a for loop over indexes ‘0’ to ‘array length - 1’ on the ‘hiding places’ array. each loop you get a hiding place at the current index, and you can retrieve a cat with that index from the cat array. The output “cat + hiding place” could be stored in a third array or map, perhaps inside a struct.