PDA

View Full Version : [AS2] I will create a game...


shaftbond
08-24-2004, 03:50 PM
Hey everyone, I am going to attempt to make a simple game and I am sure I will have multiple questions along the way, so I'll post them all in here to keep the forums tidy :).

Question 1:

In the first frame of the movie, I have:


function randyNum(){
ranX=Math.round(Math.random()*30);
ranNumX=ranX*16;
ranY=Math.round(Math.random()*17);
ranNumY=ranY*16;
}
//create random placement of pieces//
randyNum();
hero1._x=ranNumX;
hero1._y=ranNumY;
randyNum();
robot1._x=ranNumX;
robot1._y=ranNumY;


that places the hero and an evil robot randomly on a specified invisible grid. that part works. now, I want to be able to press "T" and have the hero teleport randomly somewhere else on the grid. So I created a movie clip and named it "script", placed it outside of the movie boundaries and inserted this code:


onClipEvent(keyDown){
_root.randyNum();
_root.hero1._x=ranNumX;
_root.hero1._y=ranNumY;
trace(ranNumX);
}


I know this isn't linked to "T" yet, but the number is returning undefined. Any help would be appreciated.

Curly Brace
08-24-2004, 04:07 PM
Replace the code to this:

onClipEvent(keyDown){
_root.randyNum();
_root.hero1._x=_root.ranNumX;
_root.hero1._y=_root.ranNumY;
trace(_root.ranNumX);
}