PDA

View Full Version : making a frame jump forward based on a variable


gxd4b0
10-21-2002, 01:56 PM
Heres the scene.

In my initial timeline i have set some variables. I have 3 objects who go through some random numbers. Depending on which of these objects come up with the highest number, I want the timeline to jump to a certain frame.

The problem is my timeline consists of 1 keyframe which has the following:

highestnumber = 0;

if(highestnumber==1){
//jump to frame 2 which displays Object 2 has highest number
}
if(highestnumber==2){
//jump to frame 3 which displays Object 3 has highest number
}

etc.....

obviously if I set the variable highestnumber to 0, then it cant be 1 or 2.

So my question is how can I set a variable at the start, then depending on which object has the highest number, run a particular frame.

I hope that all makes sense. If it doesnt let me know and I'll try to explain better.

Pal3rm02k
10-22-2002, 08:36 PM
can u tell more??
what do u mean by

"I have 3 objects who go through some random numbers" ?

crabcake
10-24-2002, 01:02 AM
You can do this with a function that gets called once the highest number is established, but it's unclear how you are going about comparing the numbers.

tiger
10-24-2002, 06:23 AM
i find it very helpful to name my frames instead of using numbers, just a little tip

pinkaboo
10-24-2002, 11:39 AM
Are you asking how to work out which of the 3 objects has generated the highest number and go to a particular frame based on that result?

I might have misunderstood you here but how about slapping the 3 numbers each object has spewed out into an array, and then running a sort, finding the location of the highest number in that array and jumping to frame based on that?

ie


//create an array with your values
//ie objectValues[0] == number object1 generated.
objectValues = new Array(180, 525, 882);

//sort function because array.sort only really works for strings
function sortNums(a, b) {
return a-b;
}

//function to find highest value in array
function findHighest(x) {
//creates temp duplicate array to preserve positions
tempArr = x.slice();
//calls sortNums function to arrange values in array into order
x.sort(sortNums);
//highest value will now be the last value in the array
highest = x[[(x.length)-1]];
trace("highest=" + highest);
//search duplicate array for largest number
//and return the postion in which it is found
for (var z = 0; z<x.length; ++z) {
if (tempArr[z] == highest) {
//tell mc to gotoAndStop on a frame
//dependent on result of highest number
trace("gotoAndStop (frame"+(z+1)+")");
gotoAndStop(z+1);
}
}
}
findHighest(objectValues);


any use?

-pinK