| Home | Tutorials | Forums | Articles | Blogs | Movies | Library | Employment | Press | Buy templates |
|
|
#1 |
|
Registered User
Join Date: Nov 2001
Location: London
Posts: 3
|
Hi There
I hope somebody can lend me thier expertise. I need to make a game, It's simple in concept, but I'm struggling to put the action and variables and random maths, together. The game is chopping kings and queens heads off, it's for a history site. So you have 5 different heads, popping up behind 5 chopping boards at random and using the ax attached to the mouse._x._Y you got to hit them, and hence earn points. But I can't seem to get the heads to pop up at random intervals or appear at random chopping boards. Your Help will be greatly appreciated. Ryan |
|
|
|
|
|
#2 |
|
Registered User
Join Date: Oct 2001
Location: london
Posts: 39
|
Try this, maybe it will help...
Set up your five "head" movieclips with instance names "head1" through "head5", then add this script to a dummy movieclip on the main timeline- onClipEvent (load) { // sets random time based on current value of getTimer() function setRandomTime () { now = getTimer(); delay = Math.floor(Math.random()*10000); popTime = now+delay; return popTime; } // initialise head positions and set random pop up times for (i=1; i<=5; i++) { head = _root["head"+i]; head._y = 200; head.upTime = setRandomTime(); } } onClipEvent (enterFrame) { for (i=1; i<=5; i++) { head = _root["head"+i]; // pop up head if (head.upTime<getTimer() && head.upTime+3000>getTimer()) { head._y = 100; } else { // put head down again and calculate next pop up time head._y = 200; head.upTime = setRandomTime(); } } } |
|
|
|
|
|
|
|
|
#3 |
|
The Zen of ActionScript
Join Date: Mar 2001
Location: Dublin, Ireland
Posts: 713
|
OK, say you have 5 heads, 10 locations.
Heads called H1, H2, H3... Locations called L1, L2, L3,... numHeads=5; numLocs=10; function showhead(){ // get random head head = random(5)+1; head="_root.H" add head; // get random location location=random(10)+1; // get location for the head from the location locationX = Eval("L" add location add "._x"; locationY = Eval("L" add location add "._y"; // set the position for the head setProperty(head, _x, locationX); setProperty(head, _y, locationY); Eval(head add "._visible")=true; } you can clean up the code a bit, but that'll do it for ye |
|
|
|
|
|
#4 |
|
Registered User
Join Date: Nov 2001
Location: London
Posts: 3
|
I'd really like to thank both of you for you speedy replies.
Mad A I couldn't get yours to work, I pasted the script on Frame2 with a gotoAndPlay (1) on frame 3, I put the variables on frame1. but had no luck. I couldn't get my head round why the location variables were needed, along with the location _x, when all I want is the _y value. This is the error in output Scene=Scene 1, Layer=Layer 2, Frame=2: Line 8: ')' or ',' expected locationX = Eval("L" add location add "._x"; Scene=Scene 1, Layer=Layer 2, Frame=2: Line 9: ')' or ',' expected locationY = Eval("L" add location add "._y"; if you know what I could have done wrong, which is probably not realistic, help would be appreciated. |
|
|
|
|
|
#5 |
|
Registered User
Join Date: Nov 2001
Location: London
Posts: 3
|
I'd really like to thank both of you for you speedy replies.
Mad A I couldn't get yours to work, I pasted the script on Frame2 with a gotoAndPlay (1) on frame 3, I put the variables on frame1. but had no luck. I couldn't get my head round why the location variables were needed, along with the location _x, when all I want is the _y value. This is the error in output Scene=Scene 1, Layer=Layer 2, Frame=2: Line 8: ')' or ',' expected locationX = Eval("L" add location add "._x"; Scene=Scene 1, Layer=Layer 2, Frame=2: Line 9: ')' or ',' expected locationY = Eval("L" add location add "._y"; if you know what I could have done wrong, which is probably not realistic, help would be appreciated. |
|
|
|
|
|
#6 |
|
done
Join Date: Jun 2001
Location: portland, or
Posts: 8,048
|
the error you are getting from mad_a's code is cause there is no closing paran on the eval statement... put one of these ")"right before the semi-colon (on the code for both the location X and location Y ).
__________________
tg --- what the hell was i thinking? |
|
|
|
|
|
#7 |
|
Registered User
Join Date: Nov 2001
Posts: 47
|
you are simply missing the closing bracket ')' at the end of the eval statement. add that into both lines and you should lose those errors.
.:er:. |
|
|
|
|
|
#8 |
|
The Zen of ActionScript
Join Date: Mar 2001
Location: Dublin, Ireland
Posts: 713
|
Opps!
Sorry about that. As the lads said - I left out the closing brackets... ....had to leave you something to do! ![]() |
|
|
|
|
|
#9 |
|
The Zen of ActionScript
Join Date: Mar 2001
Location: Dublin, Ireland
Posts: 713
|
gee...my code iks getting worse and worse...another error, the value for random should be one less as I am adding one to it (BECAUSE RANDOM INCLUDES ZERO)..so here is the modified code:
function showhead(){ // get random head head = random(4)+1; head="_root.H" add head; // get random location location=random(9)+1; // get location for the head from the location variable locationX = Eval("L" add location add "._x"); locationY = Eval("L" add location add "._y"); // set the position for the head setProperty(head, _x, locationX); setProperty(head, _y, locationY); Eval(head add "._visible")=true; } |
|
|
|
|
|
#10 |
|
Registered User
Join Date: Oct 2001
Location: london
Posts: 39
|
Yeah, I had a look through my code too and made a couple of tweaks.
Here's the update: onClipEvent (load) { // sets random time based on current value of getTimer() function setRandomTime () { now = getTimer(); delay = Math.floor(Math.random()*10000); popTime = now+delay; return popTime; } // initialise head positions and set random pop up times upPosition = 120; downPosition = 200; for (i=1; i<=5; i++) { head = _root["head"+i]; head._y = downPosition; head.upTime = setRandomTime(); } } onClipEvent (enterFrame) { for (i=1; i<=5; i++) { head = _root["head"+i]; // pop up head if (head.upTime<getTimer() && head.upTime+2000>getTimer()) { head._y -= (head._y-upPosition)/2; } else { // put head down again and calculate next pop up time head._y += (downPosition-head._y)/2; head.upTime = setRandomTime(); } } } I'm sure that if you combine this and Mad A's together you'll have something that works the way you want, in the meantime I put a demo of the above up at: chopping demo |
|
|
|
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| writing actionscript so flash acts like a screensaver | cherie | ActionScript 1.0 (and below) | 4 | 03-28-2004 12:41 AM |
| ActionScript Learning | StormStrikes | Other Flash General Questions | 12 | 03-04-2004 04:28 AM |
| Writing to a text file using actionscript | sharadha | ActionScript 1.0 (and below) | 1 | 08-01-2002 08:08 AM |
| french writing in ActionScript panel | micardi | ActionScript 1.0 (and below) | 1 | 01-07-2002 12:01 PM |