Adding randomly loaded variables together and more

Hello

I’m struggling with a project. I’ll try and describe it. 10 mc are loaded randomly with one of two ext.swf’s. Each time you click/drag on one, 1 of 6 questions are randomly loaded from an array into a text box on the main timeline. I need to count and add up how many of each of the 2 ext.swf’s have loaded and whether they have an x pos < or > 300. My first problem is: The question shows up in the text box when the mc is clicked/dragged but when I trace it, the question that shows in the output doesn’t match the one that’s loaded into the text box?
The second problem is a big one. I need to be steered in the right direction as to keep track of what is where on stage. I only have a vague sense of how to go about it, and combining all the bits is too much.

  1. I need to trace the question
  2. I need to say if the question is ‘blah’ do this
  3. The ‘do this’ is pretty complicated. I need to add up the #1 movies that have an x pos of <300 and the #1 movies that have an x pos of >300 and then do the same for the #0 movies. Then I need to compare a users input answer to the correct one!!!
    The question AS is in the external swf. [AS]stop();
    // Questions Array
    question = new Array(); {
    question[0] = “How many hedgehogs are in the bed?”;
    question[1] = “How many hedgehogs have rolled out of the bed?”;
    question[2] = “How many hedgehogs with curly hair are in the bed?”;
    question[3] = “How many hedgehogs with straight hair are in the bed?”;
    question[4] = “How many hedgehogs with straight hair have rolled out of the bed?”;
    question[5] = “How many hedgehogs with curly hair have rolled out of the bed?”;
    }
    out_btn.onPress = function() {
    _parent.startDrag();
    r = 0
    hog.eyeball_mc.gotoAndPlay(‘open’);
    gotoAndPlay(‘rotateStart’);
    }

out_btn.onRelease = out_btn.onReleaseOutside = function() {
_parent.stopDrag();
hog.farBottomLeg_mc.gotoAndPlay(‘wiggle’);
hog.farTopLeg_mc.gotoAndPlay(‘wiggle’);
hog.nearBottomLeg_mc.gotoAndPlay(‘wiggle’);
hog.nearTopLeg_mc.gotoAndPlay(‘wiggle’);
_global.whichQuestion = trace(question[Math.round(Math.random()*4)]);
}
[/AS]

I think it would be simpler if I removed the first two questions.
The movie clip trace AS is on the maintimeline. I know I should have made them load from an array or something more effiecient than this mass of code but I knew I could make it work doing it the long way.
[AS]stop();
//Create movie clip for 1 curly hh
//there always needs to be at least one of each
_root.createEmptyMovieClip(“hedgehog1_mc”,2);
loadMovie(“1.swf”, “hedgehog1_mc”);
movNum1 = trace(1);
hedgehog1_mc._x = 35 ;
hedgehog1_mc._y = 240 ;
//create movie clip for one straight hh
_root.createEmptyMovieClip(“hedgehog2_mc”,3);
movNum2 = trace(0);
loadMovie(“0.swf”, “hedgehog2_mc”);
hedgehog2_mc._x = 75 ;
hedgehog2_mc._y = 245 ;

//create movie clip for the random 3rd, position
//trace which mc loads and give it a name to keep track of it
_root.createEmptyMovieClip(“hedgehog3_mc”,4);
hh = Math.round(Math.random()*1);
movNum3 = trace(hh);
loadMovie(hh+".swf", “hedgehog3_mc”);
hedgehog3_mc._x = 115 ;
hedgehog3_mc._y = 240 ;

//create movie clip for the random 4th, position
_root.createEmptyMovieClip(“hedgehog4_mc”,5);
hh = Math.round(Math.random()*1);
movNum4 = trace(hh);
loadMovie(hh+".swf", “hedgehog4_mc”);
hedgehog4_mc._x = 155 ;
hedgehog4_mc._y = 245 ;

//create movie clip for the random 5th, position
_root.createEmptyMovieClip(“hedgehog5_mc”,6);
hh = Math.round(Math.random()*1);
movNum5 = trace(hh);
loadMovie(hh+".swf", “hedgehog5_mc”);
hedgehog5_mc._x = 195 ;
hedgehog5_mc._y = 240 ;

//create movie clip for the random 6th, position
_root.createEmptyMovieClip(“hedgehog6_mc”,7);
hh = Math.round(Math.random()*1);
movNum6 = trace(hh);
loadMovie(hh+".swf", “hedgehog6_mc”);
hedgehog6_mc._x = 55 ;
hedgehog6_mc._y = 265 ;

//create movie clip for the random 7th, position
_root.createEmptyMovieClip(“hedgehog7_mc”,8);
hh = Math.round(Math.random()*1);
movNum7 = trace(hh);
loadMovie(hh+".swf", “hedgehog7_mc”);
hedgehog7_mc._x = 95 ;
hedgehog7_mc._y = 255 ;

//create movie clip for the random 8th, position
_root.createEmptyMovieClip(“hedgehog8_mc”,9);
hh = Math.round(Math.random()*1);
movNum8 = trace(hh);
loadMovie(hh+".swf", “hedgehog8_mc”);
hedgehog8_mc._x = 135 ;
hedgehog8_mc._y = 265 ;

//create movie clip for the random 9th, position
_root.createEmptyMovieClip(“hedgehog9_mc”,10);
hh = Math.round(Math.random()*1);
movNum9 = trace(hh);
loadMovie(hh+".swf", “hedgehog9_mc”);
hedgehog9_mc._x = 175 ;
hedgehog9_mc._y = 255 ;

//create movie clip for the random 10th, position
_root.createEmptyMovieClip(“hedgehog10_mc”,11);
hh = Math.round(Math.random()*1);
movNum10 = trace(hh);
loadMovie(hh+".swf", “hedgehog10_mc”);
hedgehog10_mc._x = 215 ;
hedgehog10_mc._y = 260 ;

//bellpull button to check answers
_root.bellPull.checkAnswer_btn.onRollOver = function(){
_root.bellPull.gotoAndStop(‘over’);
}
_root.bellPull.checkAnswer_btn.onRollOut = function(){
_root.bellPull.gotoAndStop(‘still’);
}
_root.bellPull.checkAnswer_btn.onRelease = function(){
_root.bellPull.gotoAndPlay(‘dangle’);
}[/AS]

If someone could make some suggestions about where I should start it would be so incredible. This project is overwhelming me. I can post the FLA’s too.
Thank you to any one who can take the time.

An update…my code wouldn’t trace the random question.
the code was:
[AS]button_btn.onRelease = out_btn.onReleaseOutside = function() {
_root.newQuestions_txt.text = _root.question[Math.round(Math.random()*3)];
_global.whichQuestion = trace_root.question[Math.round(Math.random()*3)];);
}[/AS]

Making it redo the random and tracing a different question from the array.

So I changed it to this sot that it traces what winds up in the text box as a result of the random selection:

[AS]button_btn.onRelease = out_btn.onReleaseOutside = function() {
_root.newQuestions_txt.text = _root.question[Math.round(Math.random()*3)];
_global.whichQuestion = trace(_root.newQuestions_txt.text);
}[/AS]
Phew.
I’ll get there.

I assumed that putting the _global in front of my whichQuestion variable in my loaded swf would be able to be manipulated in the maintimeline. The array that holds the questions is in the root timeline. The random math that selects the question is in a loaded swf as well as the trace. The output window shows that the trace is working. There is a btn that when pressed is supposed to check which question was loaded and put the appropriate answer in the answer text box. The code is below.

[AS]//this is in the loaded swf
out_btn.onRelease = out_btn.onReleaseOutside = function() {
_parent.stopDrag();
_root.newQuestions.text = _root.question[Math.round(Math.random()*3)];
_global.whichQuestion = trace(_root.newQuestions.text);
}

//this is in the root timeline
question = new Array(); {
question[0] = “How many hedgehogs with curly hair are in the bed?”;
question[1] = “How many hedgehogs with straight hair are in the bed?”;
question[2] = “How many hedgehogs with straight hair have rolled out of the bed?”;
question[3] = “How many hedgehogs with curly hair have rolled out of the bed?”;
}

//bellpull button to check answers

_root.bellPull.checkAnswer_btn.onRelease = _root.bellPull.checkAnswer_btn.onReleaseOutside = function(){
if(_global.whichQuestion = “How many hedgehogs with curly hair are in the bed?”){
theAnswer = “yikes”;
}
if(_global.whichQuestion = “How many hedgehogs with straight hair are in the bed?”){
theAnswer = “result of some math”;
}
if(_global.whichQuestion = “How many hedgehogs with straight hair have rolled out of the bed?”){
theAnswer = “a different result”;
}
if(_global.whichQuestion = “How many hedgehogs with curly hair have rolled out of the bed?”){
theAnswer = “holy smokes”;
} else {
theAnswer = “super duper”
}

}
[/AS]
the last else works to show the ‘super duper’ so it’s not my paths, but my if statements and the global variable.

If there are any ideas out there…
thank you for them

Why won’t this code work? The only info that gets passed on to the answer text box is the last else …super duper. The trace for the variable whichQuestion shows correctly. Why won’t my ifs and if elses work?
[AS]out_btn.onRelease = out_btn.onReleaseOutside = function() {
_parent.stopDrag();
_root.newQuestions.text = _root.question[Math.round(Math.random()*3)];
whichQuestion = _root.newQuestions.text;
trace(whichQuestion);
}

_root.bellPull.checkAnswer_btn.onRelease = function (){
if(whichQuestion = “How many hedgehogs with curly hair are in the bed?”){
_root.theAnswer_txt.text = “yikes”;
}
else if(whichQuestion = “How many hedgehogs with straight hair are in the bed?”){
_root.theAnswer_txt.text = “holy smokes”;
}
else if(whichQuestion = “How many hedgehogs with straight hair have rolled out of the bed?”){
_root.theAnswer_txt.text = “holy smokes”;
}
else if(whichQuestion = “How many hedgehogs with curly hair have rolled out of the bed?”){
_root.theAnswer_txt.text = “holy smokes”;
} else {
_root.theAnswer_txt.text = “super duper”
}

}[/AS]

Use the equality operator (==) instead of the assignment operator (=). :wink:

if (whichQuestion == "whatever") {
theAnswer_txt.text = "whatever";
} else if (whichQuestion == "whatever") {
theAnswer_txt.text = "whatever";
} else {
theAnswer_txt.text = "whatever";
}

Thank you !

That does the trick. I had tried using it before in a different verison of the code and I thought the code wouldn’t work because of the (==****) but it was something else. Thank you again!.

No problem. :slight_smile:

Hi again

I have the different parts fo my movies talking to each other correctly. Instead of the questions putting in text, I’ve asked it to call the particular function for that question. That function is supposed to do the math to calculate the answer. It’s working up to the point of doing the math. I don’t know how to make them add up the movie clips depending on thier position. I am tracing which of two swf’s load into 10 movie clips, tracing their original postion and their new position that they have been dragged to.
Here is a sample of the code, but it is really wrong I’m sure. I’m trying to do just a bit at a time…there are several more things this code will have to do (check the correct answer against an inputed answer)

loaded=1 is the swf for the curly haired hedgehog,
and question 1 is how many curly haired hedgehogs are in the bed

[AS]_global.question1 = function() {
i=1;i<11;i++;
loaded = movNum+i;
if (loaded=1){
if(curPos>280){
theAnswer_txt.text = 0}
if(_global.cPos<280){
theAnswer_txt.text = “1 - don’t know”}
}
}[/AS]

Any ideas? I cna’t figure out how to make it count how many mc’s. Should I be trying to put them in a dynamic array of some sort before I ask them to add?
No clue…