# Flash shooting game question

Hi,
I am making this shoot game that shooting number does not match with the shooting objects or sometimes the number shows NaN.

For this game, first, there are two layers, Scores and balls. In the scores layers, there is script for the generate problem and control the red cross. In the balls layer, it has script for the balls's random number and control them to move from right to left and left to right.

So, How these two part script part work ? First, score layer script generate problem then send the "answer" ( script line 3 to 16 ) to the balls' layer script then ball's script will generate a same answer number on one of these 18 balls.

Then the red cross should move when the mouse arrow movie within the shooting area ( left = -398 right = -11 top = -253 bottom = 56 ). Then the red corss will follow the mouse arrow within these area. And when click on mouse, the white ball will shoot out and hit the orange ball... then if it is right answer, orange ball will be gone and scroe layers script will generate a new problem then whole game will continue......

###### Who is Participating?

Commented:
This is what I would do, get rid of all your other number gereating code and add this:

generate();
function generate(){
whichNum=random(this._parent.ducks_mc.duckNumbers.length);
eq1=random(70);
if(eq2<0){
eq2=Math.abs(eq2);
sign="+";
}else{
sign="-";
}
b=eq2;
a=eq1;
}

Billystyx
0

Commented:
Hello mingchih,
I don't quite understand what the game is about, I read most of the code and I assume you need to find the answer in the ducks. Now the problem is that when I look in the code, I see you
- look into it to see if the answer is there
- then if not, you create it again, that just doens't make sense to me. Am I missing something?

Why do you want to create an answer array if you delete it entirely just to create it again? What's the function of it?

From my humble point of view, if you have two number arrays and select numbers from them to propose the problem then you don't need to re-create the values.

ie:
myArray_A, myArray_B

get random values for myArray_A and B
copy myArray_B to duckArray
pick a random number from myArray_A
pick a random number from myArray_B
check if substracting A-B is greater than 0 (if you don't want negative values)
put the resulting number and myArray_A into the textboxes
and perform the "shoot" check when user click.

that is what i'd do.

Let me know and good luck!

Cërf.
0

Commented:
sorry, my friends account...
0

Commented:
This is my account...

Cërf.
0

DesignerAuthor Commented:
yeah, this game is just about find answer on ducks ( balls ) and shoot the answer.....
0

Commented:
So, what do you think of my idea?
Do you want to implement it?

That's what we are hewre for, huh?

Cërf.
0

DesignerAuthor Commented:
Can I ask.... can I just make question to always show minus sign ?
0

Commented:
generate();
function generate(){
whichNum=random(this._parent.ducks_mc.duckNumbers.length);
eq1=random(70);
if(eq2<0){
//eq2=Math.abs(eq2);
//sign="+";
generate();
}else{
sign="-";
}
b=eq2;
a=eq1;
}

just remove those lines I have comented out and replace them with a call to the function again.

Billystyx
0

Commented:
Really nice code Billystyx!

Have a good one,

Cërf.
0

Commented:
thanks:)
Billystyx
0

DesignerAuthor Commented:
thanks:) Billystyx

Brian
0

Commented:
no worries!
0

DesignerAuthor Commented:
hi, Billystyx
I would like to ask, if I want to have two level of game.... first level "question" number range from 0 to 20 ( ex. 1-1 ~ 20-20 ) and second level "question" number range from 20 to 60 ( 20 -20 ~ 60 - 60 ). If I pass the 1st level and should go to the second level.... How can I do that ? thanks
0

Commented:
You would need to set varaibles startpt and endpt on the _root for example, depending on level.
Then just access them in the function (where I have commented below), instead of using numbers, use those variables

generate();
function generate(){
whichNum=random(this._parent.ducks_mc.duckNumbers.length);
Rand=[];
for(i=20;i<41;i++){//these variables you would set depending on level
//like startpt=20;endpt=41, and then inside the for loop there
//you would do for(i=_root.startpt;i<_root.endpt;i++){
Rand.push(i);
}
eq1=random(Rand.length);
eq1=Rand[eq1];
if(eq2<0){
//eq2=Math.abs(eq2);
//sign="+";
generate();
}else{
sign="-";
}
b=eq2;
a=eq1;
}

Billystyx
0

DesignerAuthor Commented:
so, I put for(i=_root.startpt;i<_root.endpt;i++){  within the ducks ( balls ) area ?
0

DesignerAuthor Commented:
thanks for your last post....I would like to ask if I did right or not.....

I change from............
//give balls random number
for ( var i = 0; i < 18; i ++ ) {
var n = random( 50 )
this[ "duck_" + i ].num_txt.text = n;
this[ "duck_" + i ].num = n;
duckNumbers[i] = n;
}

to script like this ?
//give balls random number
for(i=_root.startpt;i<_root.endpt;i++){
var n = random( 50 )
this[ "duck_" + i ].num_txt.text = n;
this[ "duck_" + i ].num = n;
duckNumbers[i] = n;
}

After I change it, I got the trace shows "19- NaN=undefined"....

Did I change the wrong place ?

thanks

Brian
0

DesignerAuthor Commented:
Also, Can I make ball's number generate different random numbers after got hit each time ?
0

Commented:
hello, just posted a response to your new question (as above), but when I sent it was deleted...
anyway, like this:

_root.startpt=20;
_root.endpt=61;
var invisible;
generate();
function generate(){
whichNum=random(this._parent.ducks_mc.duckNumbers.length);
Rand=[];
for(i=_root.startpt;i<_root.endpt;i++){
Rand.push(i);
}
eq1=random(Rand.length);
eq1=Rand[eq1];
if(eq2<0){

generate();
}else{
sign="-";
}
b=eq2;
a=eq1;
}
Hope that helps:)
0

DesignerAuthor Commented:
hi,
thanks...I can see why it is not working..... Can I also ask, sometimes answer does not show up on the balls ( maybe 1 in 9 times ). How to fix that problem ? I think is it possible to generate new numbers when ball reach the end on each rows. and have answer among the new generate radom numbers.... also, about that new questions....I try to move the generate random number scripting from ball to shooting.....it is a big mass....maybe you can take a look @ http://www.brianlinstudio.com/question/numberQ4.fla.zip

thanks

Biran

Below is the question I delete -------
I have this games that question numbers show NaN and undefined. Also, It does not show random number on balls. I think it is the problem with "function generate()" under "scorekeeper" movie clip. I need different random numbers on balls after shoot each time. Also, there should be a new generate number for question. Answer needs to match one of number on orange ball..... Demo can download @ http://www.brianlinstudio.com/question/numberQ4.fla.zip thanks for any suggestions :)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.