what am I doing wrong? I randomly choose an object from among 6 objects.
I believe it on stage. I make some modification.
Then I delete the child of the structure (I think this is the problem). But when you run the test, repeated objects appear.
what can i do?
It’s in Spanish, but I think you’ll understand everything.
Did you know you can select File/Language and temporarily set your language to English.
I am not sure what you are trying to do. Are you trying to create a random monster by its name from a group of monsters that are named Monster1, Monster2, Monster3 etc?
When you remove a child of an array, say index 3, then 4, 5 and 6 move up to become 3, 4 and 5. So there will be repeats because you already have a Monster 3.
But I’m really not sure what’s going on because I can’t read the events.
thanks for the help.
Here you have an image in English.
I’m sure that by deleting a child of the structure, the rest of the indexes don’t move.
What I’m trying to do is have the 6 objects appear randomly and without repetition.
Well it doesn’t matter like I thought anyway, since I see you’re using the number in the child and not the index to make you’re monsters.
But if it’s not moving the other indexes, how is that going to work since you’re using child count -1 to choose the random numbers? If the first random number is 3 and now you have 0, 1, 2, 4 and 5 left, now the child count -1 is 4 so it will only pick from 0 to 4 and that means it can pick 3 again which doesn’t exist but it can’t pick 5 which does exist.
The random number can be repeated as long the index is being removed from the array.
If you start with 1,2,3, then if it picked 0 each time it would pick 1, 2, 3.
The array would be
1,2,3
2,3
3
Empty.
Another method is to use the array tools extension to create and shuffle an array and then pop the last element. Pop takes the last value and removes it with 1 action.
I prefer to use a hidden object for the spawn location instead of numbers. It’s easier to reference and you can move the object instead of modifying the code.
In structures, yes, because they’re not ordered. They’re keys.
With arrays your assertion is incorrect, the items shift towards the start of the array.
Also, you haven’t made the changes I indicated. Until you do that, you’ll get the wrong number being written to the screen.
No he wants the index chosen written first like:
Index 0 Monster1
In the video it clearly shows the same indexes being called again and no Monster name being written and no Monster being spawned at that time, as if the array is not shifting forward correctly when a child is removed.
So what if this is the answer right here. The variable objetos_creados is a structure with children named 0-5, not an array! Then when it takes removes “index” 0 and then chooses “0” as the next random number again, that’s why it’s not creating another monster.
thanks friends.
I’m going to change it to an array. And I am also going to make the changes indicated in the image. I’m a little busy now. I’m not at home. I will keep you informed.