I have a peculiar situation at hand. I crated a sprite, gave it turret behaviour, added two different bullet sprites (red and green) and want the turret to shoot a random bullet each time. (there is also an irrelevant trick where turret shoots in irregular intervals as you will see.) Below is what I came up with:
global variable what to shoot = 1
on turret shoot
whattoshoot = 1
create object redbullet on layer 1 at enemybird image point 1 x and y
set redbullet angle to enemybird.angle
set turret rate of fire to 4-random(1,2.5)
set whattoshoot to round(random(0.9,2.1)
whattoshoot = 2
create object greenbullet on layer 1 at enemybird image point 1 x and y
set greenbullet angle to enemybird.angle
supposedly the enemybird will either shoot a green bullet or a red bullet, then random will create between 0.9 and 2.1 and round will change it to either 1 or 2. so next time relevant bullet will shoot. And it works! But sometimes, it shoots both bullets together. There is no other event outside of these related to turret behaviour or bullets. Does anyone have any idea what I could be doing wrong?
Wait, why are you declaring whattoshoot so far down the list of actions. Surely it should be set first, as the shooting action takes place?
On turret shoot -> set whattoshoot random etc.
whattoshoot = 1...
whattoshoot = 2...
Geometrix, I moved it up but it didn't work either. Though I really don't know why I couldn't think of doing it the sub-evet way. I started only couple days ago, so fresh... Thanks for the help, I will try it that way.
Develop games in your browser. Powerful, performant & highly capable.
It worked! Thanks Geo!