Page 1 of 1

Timers and Rand Function ??

PostPosted: Sat Feb 21, 2004 8:19 am
by Just4Fun
Is it possible to have an actor appear and disappear at different random screen locations for a time period of 10 seconds? If so, how is it done ?

I've checked the forum, the demos and the tutorials without success. TIA :?

One test

PostPosted: Sat Feb 21, 2004 9:30 am
by ingsan
i'm not a boss at programming but try this little little code of mine.

Add actor "MainActor"

Add Event Create Actor
Add Action Create Timer // and create ur timer.

Now :
Add Event Timer
Add Action Script Editor and write :

Code: Select all
x=rand(+-xscreen);
y=rand(+-yscreen);


It's done.

MainActor should change position and get a random one after timer. As u see no need for me to destror actor.U can eventually Destroyactor and after Destroy, Create it elswhere using the code that i've gave u.

...please, don't laugh at my poor code :oops:
I hope i helped u. :wink:

PostPosted: Sat Feb 21, 2004 7:04 pm
by Just4Fun
ingsan:

Thank You! That was EXACTLY what I needed. I'm still pretty confused about the timer and how to use it. I've been studying jazz-e-bob's "shark" timers, but they aren't quite what I was after and they are sophisticated enough that most of them confused me more than I already was. I appreciate your extra effort in taking the time to reply.It's hard learning how GE works, but it is also great fun to make a break through in figuring out a solution to a problem. Thanks Again. :lol:

PostPosted: Sat Feb 21, 2004 9:06 pm
by ingsan
Don't thank me it's normal :wink:

For the timer, just ask urself :

Well, i have created a Timer (Timer A). What can happen when i call that timer of mine ?

Which means : On EVENT Timer, what can i make ? and u can justHaveFun after that ! :lol:

PostPosted: Sun Feb 22, 2004 2:49 am
by Just4Fun
My image is moving to random screen locations...but the locations are only in the upper right of the screen. I've tried modifying the math in the above script but that hasn't accomplished full screen movement. I need random appearance all over the screen. I think this has to do with the xscreen / yscreen co-ordinates or maybe x,y. :?

Any more ideas?.....TIA

PostPosted: Sun Feb 22, 2004 9:11 pm
by makslane
x = rand(view.width) + view.x;
y = rand(view.height) + view.y;

PostPosted: Sun Feb 22, 2004 10:19 pm
by Just4Fun
Perfect! Thank You. :lol:

* Now, onto the next problem...

Re: Timers and Rand Function ??

PostPosted: Thu May 07, 2015 1:56 pm
by Zivouhr
Helpful information, thanks. Noticed the thread is 12 years old, but it's still useful! :)