A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: random - remove used

  1. #1
    Senior Member gordonart's Avatar
    Join Date
    Jun 2003
    Location
    Sweden
    Posts
    267

    random - remove used

    I have this random-code that make the player jump do 6 different frames in the movie.

    unction randNum(nMin, nMax) {
    return Math.round(Math.random() * (nMax - nMin)) + nMin;
    }
    /////
    pil2.onRelease = function(){
    s=new Sound();
    s.attachSound("knack");
    s.start();
    _root.gotoAndStop("go" + randNum(1, 6));

    How can I write a code so that when I have been on the go2 frame don´t go there anymore?

    /Mattias
    Mattias Gordon
    illustrator/ animator

  2. #2
    :
    Join Date
    Dec 2002
    Posts
    3,518
    Does not go to page currently on, randomly goes to another page.
    Code:
    function randNum(nMin, nMax) {
    	return Math.round(Math.random() * (nMax - nMin)) + nMin;
    }
    pil2.onRelease = function() {
    	s = new Sound();
    	s.attachSound("knack");
    	s.start();
    	newLoc = "go" + randNum(1, 6);
    	while (curLoc == newLoc) {
    		newLoc = "go" + randNum(1, 6);
    	}
    	curLoc = newLoc;
    	_root.gotoAndStop(newLoc);
    };
    - or -
    Randomly goes to each page, then stops.
    Code:
    function randNum(nMin, nMax) {
    	return Math.round(Math.random() * (nMax - nMin)) + nMin;
    }
    var rndArray = new Array();
    var i = 0;
    while (i++ < 6) {
    	rndArray.splice(randNum(0, rndArray.length),0,"go" + i);
    }
    trace(rndArray);
    /////
    pil2.onRelease = function() {
    	s = new Sound();
    	s.attachSound("knack");
    	s.start();
    	_root.gotoAndStop(rndArray.pop());
    }

  3. #3
    Senior Member gordonart's Avatar
    Join Date
    Jun 2003
    Location
    Sweden
    Posts
    267
    I tested this but had problems with some other codes that I used on every page.
    I found a way move to another fram with this code:
    function randNum(nMin, nMax) {
    return Math.round(Math.random() * (nMax - nMin)) + nMin;
    }
    /////
    this.onEnterFrame = function(){
    s=new Sound();
    s.attachSound("knack");
    s.start();
    _root.gotoAndStop("go" + randNum(1, 6));
    }

    Can You add something to this so that You don´t come back to the last fram you just came from. It´s ok if you get back to the same frame later on but to avoit getting the same randomframe after it self.
    Can that be done?

    /Mattias
    Mattias Gordon
    illustrator/ animator

  4. #4
    Senior Member gordonart's Avatar
    Join Date
    Jun 2003
    Location
    Sweden
    Posts
    267
    One idea ( maybe a little complex but..) would be to have 6 different frames that you go to before a new frame. There you can specify which rand-frame there are.
    If yoy want to avoid frame 4 among frames 1-6 how could you write that in the code?
    Mattias Gordon
    illustrator/ animator

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center