My game is top down, I’m trying to make it spawn 1 out of several power ups on an object
I’ve tried using the craete an object from its name but it doesn’t seem to work and I’m out of ideas, also I have already put them inside a group so if I can get the power up spawn to work I will turn it into a global object in the future.
Can you show us your spawn events?
When you use create by name there are at least 2 methods. I usually use the first.
Name your spawn objects sequentially like spawn0 to say spawn5
Then for the name in create by name use “spawn” + ToString(Random(5))
The 2nd way keeps the name as they are. Create an array with the names of the objects in the group. Then use
create by name arrayName[Random(6)]
You can use the expression that counts the number of children instead of 6. It’s just that I don’t remember the exact syntax for it.
The array method has the advantage of the ability to remove elements from the array so the object is only spawned once. You can also add names.
For the second method do I have to make the array into a global array since the objects that I want to spawn are already in a global group object?
If you’re using multiple scenes and want them to share the same list then use Global variables. It’s just the scope of the variable. It doesn’t care what’s stored inside them. Scene variables are specific to one scene. Global ones can be accessed from any scene.
I have managed to get the the first method working but I still cannot figure out the array method, can you please give a visual example? I’ve found one tutorial of it on youtube but sadly I can’t get mine to work.
for now I’ll stick to the first method but I also want to know how the global array method works too.
currently my power ups aren’t global variables but only my group of guns are, also I would like to know about the fire bullet expension, does it allow for incremental increases for the bullets, multishots, accuracy, etc? because my powerups revolves only on those for example multishots, and ammo. like lets say currently the player gun only fires 1 multishot and he picks up 2 upgrades of multishot so now the gun shoots 3 multshot of bullets, I was wonder if the upgrades I can put can do incremental of +1 to the firebullet stats?
Using 3 objects name c,d, and e and an object list named group that contains the 3 objects. Nothing needs to be on the scene,
Global variables. (Rand doesn’t need to be global, But I thought it would be simpler to explain if everything was global)
Arrays start at zero. So, the random number is to count -1
I didn’t see the bullet part. Your powerup objects could have any variable(s) you want. if a variable is true or a certain text then change the fire behavior parameter. or it could change the players’ options. That would be more permanent if you put all of the variables into a structure it would make them easier to save should you decide to save the updated player stats.
I tried this out and it still doesn’t work
Do you have all of the objects in a group named PowerUps that match the elements in the array exactly ?
Sorry late reply, it’s working now I had to change the object names to something simpler, for some reason it doesn’t work even if I copy pasted it. Also I gotta ask can you explain what does “Rand” do? and what if I want to add another child to the array what do I have to change?
Rand is just the name of a variable to hold the random number. You could put the Random() part where Rand is. Variables can help break things down into more readable events or store the value if you need to use it later. Like in my 2nd example, it’s used to remove the element or child from the array.
Since it creates a random number based on the size of the array, that part should work whether you add or remove children. I know I sometimes say children or elements. They’re the same. I’m used to calling them elements.
To add children you can use the Variable screen or add text variable
It takes the Variable name and the text value. The text value can be text either in quotes like “duck” or a variable like GlobalVariableString(variable) or using the new way of entering variable just the variable name as long as the variable is declared in the variable screen.