Hello, its your girl, back with another question!
I am so, so close to figuring this one out I can feel it, but I’m still stumped, and couldn’t find a previous example for help.
So, when you attack an enemy, I want it to drop coins. It works just fine with a singular coin, but I’m trying to figure out how to spawn multiple coin objects at random.
(My super duper basic coin creation. I set it up with scene variables, so if I choose, I can make a scene variable of Coin=2, have a higher amount of coins fall)
I know very, very generally about the RandomInRange option for other things, but I have no clue how to apply it here. I suspect it’s what I’ll need to use, but I’m just stumped on how to use it.
Thank you so much in advance, yall are always life savers!
Okay first of all, add variable to enemy object and call it “NumberOfCoins”
Then, add “Repeat” event that will trigger when your enemy dies.
And finally add conditions and actions as shown below.
So now every time when you kill an enemy, it will spawn random amount of coins.
You can set min and max amount of spawned coins in “RandomInRange” action, just like positions. The ones I set are just for example.
Awesome thank you! I was hoping I wouldn’t have to do an object variable (just because it would mean editing each individual object I’ve already placed on the screen) but it does seem like the proper way to go about it. Thank you, I’ll work to implement what you wrote here!
Okay, I did what you said, and most of it came out just as you described! Enemies have been spawning a number of coins in the range I write, and I double checked it with a couple ranges. Now I find myself in another bit of a pickle.
Some enemies drop coins, and some don’t. Even if both enemies are a ‘bee’ or both enemies are a ‘box’.
I was trying to decide how to handle triggering the coins, so I added a second ‘Dead’ variable to my enemy. It’s called ‘SlowEnemyARROWS’, but it’s actually a collection of enemies all in one object.
Shown in the example above, if the number of the animation is 1, that’s the death animation of my ‘bee’ enemy. If the number 3, it’s the death of my ‘box’ enemy. But randomly, some enemies just. Don’t put out coins. At first I assumed it was because a bee playing the dying animation was still happening when I killed another bee, but nope. I’m not actually sure, and I’m stumped again.
This is how I copied your example, by the way. Thanks so much for the help!
EDIT: I also attempted to put the ‘Dead’ variable in the specific condition when the enemy dies, but that made even weirder things happen, so I’m just unsure.
You don’t really need to edit every single object on the screen. Just objects in the resources list.
Anyway, assuming that you are deleting enemies after their death, it would be better to spawn coins after that action. No need for additional checks, and generally better approach.
If you need help with that, you can post screenshot here of enemies death event and I’ll help you set that up.
Oh dang, I didn’t realize I could edit that in the resources list! See, this is why the forums are so helpful.
Okay, so I’m including a screenshot of the two forms of death of that particular enemy. Either you jump on them, or hit them with your weapon. It’s only a one hit kill, but eventually I’m going to have enemies with higher health, and I’ll have to figure out a better approach there.
Thanks again for helping out, I want to make my game the best it can be!
You can easily use trigger once as main event instead of sub event because the actions that you have there should still work so no need to have sub event for that. This is the second way of checking your events as shown below.
If you do decide to leave it this way as it is, and just add coin generation, you can use option 1 (First image below).
Quick question tho, are you deleting your objects (enemies) after they die?
EDIT: For some reason second image can’t be zoomed in like first one, so you can use this link to open it.
Hey, just tried option one, and it works perfectly! I’ll keep playing with it, and add the coins spawning to more enemies, to quadruple check it functions alright! Thank you, this has been a lifesaver!
And yup, all enemies once they reach a zero opacity, get deleted! That code is just in a different section of my code.