Generation problems

I’m reposting this in a less convoluted form.

All I want to do is prevent more than one instance of the Bonus movieclip from being on screen at the same time. Since Bonuses are randomly generated, though, this poses a problem, as sometimes the calculation wants to make more than one at once.

So, I thought that a bonusTest variable could control this.

  1. if bonusTest = false, then it stops checking to see if it should create a Bonus, and no more are created.
  2. Once the Bonus is shot and removed, bonusTest = true, so that another one can appear.

But… it doesn’t work at all. Here’s all my Bonus code, what could be wrong?


// Bonus variable
bonusTest = true;
// Bonus creation
createBonus = function (x, y) {
	bonusTest = false;
	var bon = this.attachMovie("bonuslink", "Bonus", 102);
	bonus._x = mf(mr()*400);
	bonus._y = -80;
	bonus.rate = random(3)+1;
	bonus.onEnterFrame = bonus.ymove;
	bonus.onRollOver = bonus.cursorColourOn;
	bonus.onRollOut = bonus.onDragOut=bonus.cursorColourOff;
	bonus.onPress = bonus.getShotI;
	return bonus;
};
// shooting
MovieClip.prototype.getShotI = function() {
	bonusTest = true;
	this.cursorColourOff();
	removeMovieClip(this);
};
// Make stuff!
this.onEnterFrame = function() {
	iFreq = mf(mr()*100);
	if (bonusTest=true) {
		if (iFreq == 99) {
			createBonus();
		}
	}
};

Yep, well, it doesn’t work. The Bonuses just keep on getting created like crazy and bonusTest is never checked. :frowning:

Well, I’ll keep plugging away at it, but any tips are appreciated :slight_smile:

  • wobbly

Let us breathe deep in enlightenment as we examine the monumental foolishness of WobblyFork and his ActionScript adventures.

While a lesser Fork might be tempted to delete this embarassing post, I will instead post a correction, so that future generations do not make such a mistake.

if (bonusTest=true)

DOES NOT EQUAL

if (bonusTest==true)

:beam:

There should be a test before Macromedia trusts some people with their software… :wink:

ever-facetious,

  • wobbly