Hello!
I am trying to spawn random objects in my game, from an Object Group. I using the Create Object by Name action, but the objects in the group do not have a naming convention of a string ending with a number. So, I am using the approach of creating a structure variable, which keeps a number as the ‘key’, and the object name in the group as the ‘value.’ My approach is similar to the answer in this post: https://forum.gdevelop.io/t/create-random-enemies-from-a-group/12348/5
However, I’m noticing that when I try to create the object like this:
VariableString( Enemies[ ToString(Random(2)) ] )
the object does not show up on the screen. For example, here is my screenshot of the code for that action:
The structure variable is called SpawnableArray (I initially was going to make it an array rather than a structure), and the highest index is 2. I also noticed that if I display the value of VariableString(SpawnableArray.2) as text on the screen, a proper name shows up in quotation mark, but it seems like the it chokes when trying to use that name to create an object.
Here is my structure variable and the object group, so you can see the object names (I don’t have all of them in the structure variable, I just wanted to start by adding a few to make sure I could spawn them):
https://ibb.co/4TZfPVk
Any ideas about where I might be going wrong?
Thanks so much!