Runing Random functions?

Talk about making games.

Runing Random functions?

Postby bat78 » Mon Mar 04, 2013 1:45 pm

Hmmm.. i was wondering all the time is it possible and if is then how to make an specific actor to run function in random time.
It is like % of running the function each 2 seconds or random selecting the time to run the function 1 - 10 seconds idk..
So.. is it possible?
The future of "Game-Editor" here
User avatar
bat78
 
Posts: 816
Joined: Sun Dec 14, 2008 9:13 pm
Location: Bulgaria, Sofia
Score: 88 Give a positive score

Re: Runing Random functions?

Postby skydereign » Mon Mar 04, 2013 7:42 pm

You can use gE's random timer to do this, or just use random.
Code: Select all
if(floor(rand(30))==0) // <-runs 1/30 the time
{
    function();
}

If it is in draw, then that would trigger 30 times per second.
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Re: Runing Random functions?

Postby bat78 » Mon Mar 04, 2013 7:47 pm

Hey btw :D
so it should be in draw.. I see it work.. i can't get used to that script.. it is lil different from my main Pawn C++ :cry: sorry for the silly threat.
Last edited by bat78 on Mon Mar 04, 2013 7:49 pm, edited 1 time in total.
The future of "Game-Editor" here
User avatar
bat78
 
Posts: 816
Joined: Sun Dec 14, 2008 9:13 pm
Location: Bulgaria, Sofia
Score: 88 Give a positive score

Re: Runing Random functions?

Postby skydereign » Mon Mar 04, 2013 7:49 pm

bat78 wrote:so it shouldn't be in draw?

Just curious, why would you say this? In general it actually would be better to use random timers, instead of draw (or use consistent timers, using that code). You said you wanted this to happen all the time though, so the use of draw seemed appropriate.
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Re: Runing Random functions?

Postby bat78 » Mon Mar 04, 2013 7:51 pm

Yea, i am lil bad at English and i had to think a bit of it.. but i edited it already. yours code work fine enough in draw. (+1)
The future of "Game-Editor" here
User avatar
bat78
 
Posts: 816
Joined: Sun Dec 14, 2008 9:13 pm
Location: Bulgaria, Sofia
Score: 88 Give a positive score


Return to Game Development

Who is online

Users browsing this forum: No registered users and 1 guest