Active TopicsActive Topics  Display List of Forum MembersMemberlist  Search The ForumSearch  HelpHelp
  RegisterRegister  LoginLogin
PowerHome Feature Requests
 PowerHome Messageboard : PowerHome Feature Requests
Subject Topic: requested functionality Post ReplyPost New Topic
Author
Message << Prev Topic | Next Topic >>
npavkov
Groupie
Groupie


Joined: February 29 2004
Location: United States
Online Status: Offline
Posts: 91
Posted: October 12 2005 at 19:33 | IP Logged Quote npavkov

Dave... I would like to schedule a timed event to happen say in 3 hours, however I would like to apply the offset (random) within 10 mins of the 3 hour scheduled time... could that be included in the next beta????? or is that possible now???

Back to Top View npavkov's Profile Search for other posts by npavkov
 
dhoward
Admin Group
Admin Group
Avatar

Joined: June 29 2001
Location: United States
Online Status: Offline
Posts: 4447
Posted: October 13 2005 at 15:59 | IP Logged Quote dhoward

Nick,

Are you referring to timed events created on the fly from the CREATE TIMED EVENT macro command or the ph_createtimedevent function?

If so, then this can be accomplished easily enough with the existing code.

To have a timedevent happen 3 hours in the future, plus or minus ten minutes, use the following:

ph_createtimedevent(0,"YOUR MACRO ID",ph_relativedatetime(today(),169 + rand(21)))

Now you're probably wondering, how does the above function work? The ph_createtimedevent function takes 3 parameters, the first two being easy enough to understand. The third one is a datetime value for when the timedevent should fire. Since we want to fire 3 hours from the current time, plus or minus 10 minutes, we need to first convert hours to minutes. This gives us 180. Plus or minus 10 would give us 170 to 190, a twenty minute span. Since this is a random span, then we'll use the rand() function. This function takes a value and returns a random number between 1 and the value passed inclusive. So if we want a variable number of minutes between 170 and 190, then we must have a base of 169 plus a random number from 1 to 21. This gives us: 169 + rand(21). We use the ph_relativedatetime function and use the current datetime (the today() function) plus the number of minutes in the future to come up with our timed event.

This same principle can be applied to the CREATE TIMED EVENT macro command as well.

HTH,

Dave.
Back to Top View dhoward's Profile Search for other posts by dhoward Visit dhoward's Homepage
 

If you wish to post a reply to this topic you must first login
If you are not already registered you must first register

  Post ReplyPost New Topic
Printable version Printable version

Forum Jump
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot delete your posts in this forum
You cannot edit your posts in this forum
You cannot create polls in this forum
You cannot vote in polls in this forum