-
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
-
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());
}
-
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
-
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?