I’m testing a system that randomize enemy sprites and their weapons. Each objects has 4 sprites (For Enemy: enemy1, enemy1 dead, 2, 2 dead) (For their weapon: gun1, gun2, gun3, gun4) and two object variables on the Enemy object (enemyIndex and enemyGunIndex). Right now, the weapon doesn’t have the FireBullet behavior which I’m planning to add soon. Here’s my current event editor screen:
Note: there are 4 Enemy objects on the scene.
Update:
I’ve somehow managed to get the randomizer right. Here’s the new randomizer event:
I even added FireBullet behavior to the enemy’s weapon as well, plus two more weapons to make the randomizer even more noticeable. I want to set each of the enemy’s weapon stats using object structure variables. Here’s a screenshot of the stats structure variables:
And here are screenshots on how I make the weapon shoot at the player and set the stats:
The new problem now is, sometimes the shotgun stats don’t work and instead works on the MG stats. Plus, all the weapons shoots either only red bullets (EnemyBullet 0,1) or yellow bullets (EnemyBullet 2,3).
This way of handling stats is going to blow up fast. You already have a structure with all the information… instead of creating a separate event for each gun, you could have a single event that accesses the structure dynamically:
Condition: variable newGun of EnemyGun is -not- equal to "none"
Actions:
Set animation of EnemyGun (by name) = EnemyGun.newGun
Change bullets per shot = EnemyGun[EnemyGun.newGun]["bullet"]
Change cooldown = EnemyGun[EnemyGun.newGun]["fireRate"]
Change arc = EnemyGun[EnemyGun.newGun]["fireArc"]
change variance = EnemyGun[EnemyGun.newGun]["spread"]
set variable newGun of EnemyGun = "none"
Now anywhere in the events you can change the EnemyGun’s variable newGun to any name that’s in the stats. (“pistol”, “MG”, “SG” and so on). I find it convenient to also name the animations accordingly and use the animation-by-name actions for clarity… keeping track of meaningless indexes is a pain.
Now as for your actual problem, I’m not sure why it is happening. Your events are a little confusing to be honest:
- You are abusing the “repeat for each” event… this should be used AFTER filtering out objects. So for example, you might have a condition “Enemy variable Attack = 1”, then a sub-event “repeat for each”.
- It makes no sense to repeat for each enemy and then pick a random enemy. If you want to randomize all the enemies, the pick-random should be removed. If you want to pick a few random enemies, do “repeat X times” and then pick a random under that.
- There’s no point to looping over the dead enemies. Start with a condition that checks for enemies that are alive. Then repeat for each. Also, you have repeat for each enemy, twice in a row. Just combine them and do all processing at once.
- You are setting enemyIndex to a random value of 0, 1, or 2. But index 1 is supposed to be a dead enemy according to your comment. Is this intentional?
- You have a condition that is always true. “The variable enemyGunindex of Enemy = Enemy.enemyGunindex”. Obviously, the variable always equals itself. If this was intentional then just having a blank condition would be sufficient.
- I’m confused about the second part where the Gun stats are being set. You are also changing the animation of EnemyBullet. But, I don’t see where any EnemyBullet were picked from conditions. If no filtering was done then these actions will act on all EnemyBullet in the game.
Sorry, but, what does the action "set variable newGun of EnemyGun = “none” " mean? And how does the EnemyGun[EnemyGun.newGun][“bullet”], [“fireRate”], etc. access the stats when my EnemyGun sprites are named like these?
It is intentional.
newGun is just a variable I made up and could be anything you want. The idea is to give the object (enemyGun) a variable that you can use to trigger changing the stats. When newGun is set to anything other than “none”, it will read the new stats from the structure and then set newGun back to “none” (to avoid having the event fire constantly).
The animation has no connection to the structure variable. Instead of hard-coded values that you used (EnemyGun.SG.bullet) I am using a variable (EnemyGun[variable][“bullet”]. I prefer to make things easy for myself and give the animations the same name as found in the structure, but if you don’t want to do that you could add another data point to the stats to store the animation name.
This way you can set the variable to “SG” and the event will load the stats under “SG” in the structure. You can add new guns indefinitely without changing the events, and if you do want to modify the events then you won’t have to do it for every single gun.