Page 1 of 1

create an actor with moving left or right randomly?

PostPosted: Mon Jan 14, 2008 3:49 pm
by Game_amateur
I am a beginner, i am trying to create an actor, that moves left or right randomly, how can i make it? (a mouse created and move to left or right randomly)
I tried the script editor be4 like below:
x=rand(2);
if (x==1) moveto(-125,0);
else moveto(125,0);

Who can help me the syntax or another way to do that because i havent been succesful yet? THanks alot

Re: create an actor with moving left or right randomly?

PostPosted: Mon Jan 14, 2008 4:04 pm
by asmodeus
Use this code:
Code: Select all
int randomly = rand(2);
if(randomly==0) xvelocity = -5; // write instead of "5" the speed, that you want.
else xvelocity = 5;

Re: create an actor with moving left or right randomly?

PostPosted: Mon Jan 14, 2008 6:54 pm
by Fuzzy
xvelocity = 5*(rand(3)-1);

Re: create an actor with moving left or right randomly?

PostPosted: Tue Jan 15, 2008 7:56 am
by Game_amateur
Thanks so much for your helps

Re: create an actor with moving left or right randomly?

PostPosted: Tue Jan 15, 2008 8:03 am
by Game_amateur
Just one more question:
How can i make a delay function in the script editor.
Like
......
wait(1000);
DestroyActor();
...

Re: create an actor with moving left or right randomly?

PostPosted: Tue Jan 15, 2008 12:20 pm
by makslane
You need to create a timer and the code will execute when in the timer event.

Re: create an actor with moving left or right randomly?

PostPosted: Wed Jan 16, 2008 7:49 pm
by tufif
And you can make the timer random too