[FMX] Randomness help, variable problems

I’m a brand new AS kid here, haha, like, started last week, but I am working on a science fair project on random stuff, blah blah, heres the meat of my problem.

I have three movies that need to be randomly selected and then played.

These three movies must be played after a button click. Here’s how i set up the script for setting the randomness for the variables. (i dont know how you guys did that nifty code tag thingy, so I’ll just paste it into here)

//set beaker variable
Beaker = random (3) + 1;

//Beaker Movie script
if (Beaker == 1) {
	beakerGo = "revealBlue_mc" ;
	beakerColor = "BlueMovie" ;
}
if (Beaker == 2) {
	beakerGo = "revealRed_mc" ;
	beakerColor = "RedMovie" ;
}
if (Beaker == 3) {
	beakerGo = "revealGreen_mc" ;
	beakerColor = "GreenMovie" ;
}
//End Beaker Movie Script

ok, so that sets even more variables according to what the random number that Beaker variable comes out with. An explanation of the variables.

Beaker - just my random number holder
beakerGo - thats the actual instance label of my movie clip on the stage
beakerColor - thats the label i gave inside the movie clips mentioned above.

Now I head on over to my buttons that I want to play, and I’ve done this code here, inside the buton instance.

Here’s an explanation of what I’m wanting my button to do. First I want the button to make itself, and the things behind it to dissappear by going to frame labels that basically have nothing in them and stop the appropriate movie clips there. Then I want it to bring in the randomly chosen of 3 movie clips. Heres the code that I’m butchering, haha.

on (release) {
	_root.CPD_mc.gotoAndPlay ("CPDVanish");
	_root.hide_mc.gotoAndPlay("HideVanish");
	_root.beakerGo.gotoAndPlay ("beakerColor");
}

yea, i’ve got a lotta unecessarry stuff in there, but i am not really sure how to do it correctly, so I was just being absolutely sure and using root paths. Can anyone help me out here and tell me how to take the variable and inject it into a path so taht it will play a movie clip and a label inside that movie clip (obviously from my bad code there, 2 variables are used, but if you know of a better way, by all means speak! ).

Thanks so much in advance!

Welcome to kirupaForum, WarpSpider! :slight_smile:

I think you have the idea, but there are a couple of slight problems in the code.

Since you’re storing the instance name (as a string) in the “beakerGo” variable, you’ll have to use the array access operator ([]) to target the instance by its name. And remove the quotation marks around “beakerColor”, otherwise Flash will attempt to send the playhead to a frame labeled “beakerColor” instead of the frame label stored in the variable.

_root[beakerGO].gotoAndPlay(beakerColor);

…Anyway, I’d use arrays to store a reference to the movie clips and the frame labels:

beakerGo = [revealBlue_mc, revealRed_mc, revealGreen_mc];
beakerColor = ["BlueMovie", "RedMovie", "GreenMovie"];
beaker = Math.floor(Math.random()*beakerGo.length);
//
on (release) {
	beakerGo[beaker].gotoAndPlay(beakerColor[beaker]);
}

=D !!! I LOVE this forum/website! Thx so much, will try that at school!

=( not workin, haha.

I went ahead and put the code into the main timeline, and then into the button, and it wont disply a thing. the button doesnt even make anything play, and I’m losing my mind trying to figure this out, lol. I think the arrays are totally an improvement, but I can’t seem to get them to work, please help! Thanks so much in advance! Also, I have my variables displaying the whole time so i can check them, and i get this weirdness for beakerGo:

_level0.revealBlue_mc,_level0.revealRed_mc,_level0.revealGreen_mc

whats that level 0 thing about and is that messing up this code?

_root[beakerGO].gotoAndPlay(beakerColor);

HAHAHAHA! I figured it out! My variables were assigned on the main timeline, well my button is inside the movie clip, so its a completely different timeline. I just put “_root.” (without the quotes) in front of every one of the variables, and BANG! My little scientist held up his hidden Beaker! YAY! Haha, programming is so awesome (if you read above, i said I’m a new AS kid, im really a new programming kid all together, hahaha)! Thanks again! Couldn’t have done it without the array codes, haha! Life Saver!

…I wish I had flash when I did my science fair projects… :frowning:
All I had to use was QuickBASIC…
Good Luck :smiley:

haha, yea, this one is neat, gonna make it track results and such. Then I’ll bring my iBook to class and completely replace my science board with nice animations and stuff, I’m gonna blow it away, haha. We’re doing probability and statistics, and I totally proved our hypothesis wrong, but I learned something at the same time, kinda cool. We said that a computer could guess better than a human, because a human has things that influence it, and a computer really does guess, where a guess in its rawest form is completely random. A human will see a coin flipped 10 times on heads and say man, tails is way overdue. Made sense to both of us at the time. A little research and a few hours later, and we’re seeing that its always random no matter what. And eventually, after enough tests, you’ll see the same results even out with both computer and man, and not only that, the chaotic random numbers actually make a smooth bell curve. So it turned out to not be a flop, but now I’m just making the program pretty and with little scientists and hidden beakers. I’ll post a link soon, haha. Can’t wait, I’m afraid I’ll run into trouble with my graphs though, lol. Ah well, all a learning experience. I love this board!

You could have a picture of a jar of X coins, and when you click on it, they fly up in the air, and flip, and land on a table, and the computer tallies up how many are on heads, and how many are on tails. If you do it over, and over, and keep a list, you’d be surprised at the results.
I had a friend that did something similar, he used UNO cards, to determine the statistics of someone coming up with certain cards, and so on… a few years later, when Magic: The Gathering came out, he started playing, and became one of the best players that I knew, back when I played. So you can learn something from science… :wink:

haha thats awesome! So he figured out the probabilities of the cards he was going to get and played ahead of the game is what I’m guessing he learned to do, that is definitely very cool. The coins suggestion, well, too late, haha. Realy good idea though. I did three little goofy scientists, and you gotta guess which one has the beaker, and they move around like its a shells game, lol. It’s pretty neat. But the program really only looks for whether you were correct or not correct, haha. So its exactly the same as heads or tails and such. You play four games, and then the computer plays four games, and the results are compared after about 50 or so people try at it. Today during Chem, I grabbed a sheet of paper and starting brainstorming how to make the graphs dynamic, and decided on using arrays again. I love programming, haha! Anyways, sorry for yacking yur ear off, I’m just brand new to it all and pretty excited. =p thanks sooooo much for the help all!