Item random generation from Group

The question is why in the first case the object is created on mouse click, but not in the second case? “item_” doesn’t work either.


Because in the second example you are creating object names of “item1”, “item2” etc, which aren’t the names of objects in the group.

If you have names without sequential numbering, I suggest you put the object names into an array, and then select a random entry from the array.

Yes, I have already numbered objects before - and then everything worked. But I couldn’t understand the difference. It turns out he chooses by the number of the object. I still don’t understand arrays well, so I will do it through the numbering of the group or the animation number.
And if through an array, then what to write in action? I assigned an array in the scene variable and entered these 5 items into it.

This documentation may help:

A couple of things:

  1. Don’t check the number of children in an array with RandomInRange(0,4) That will take a random number every time it checks. You want a fixed number, so replace RandomInRange(0,4) with just the number 4.
  2. You are adding the same bit of text to the array - the word “item”. You’ll need to add each object name manually. There is no easy way round it, sorry (unless you use a file, but that won’t help for web based game)

You’ll need to do something like:

Thanks for the help. Until I learn the engine and arrays better, I will use more simple options.