Jump to content

- - - - -

Random trigger times

  • Please log in to reply
1 reply to this topic

#1 acalbear



  • Registered
  • PipPip
  • 36 posts

Posted 29 March 2008 - 10:39 PM

Earlier I requested a way to have lights turn on at a given time (e.g.sunset or 7pm) + or minus a few minutes to avoid predictability in the schedule. As there was nothing available I drafted the following script that you can use in other scripts or do as I did and embed it into a customized block that you can use in your object diagrams to devise scheduled scenes:

If sysevent.newVal Then

this.toggle = (Int((2) * Rnd + 1))
this.Random_Minute = (Int((this.MinuteRange) * Rnd + 1))

if this.toggle = 1 then
this.OutTime = This.InTime + (this.Random_Minute/24/60)
this.OutTime = This.InTime - (this.Random_Minute/24/60)
end if
End If

  • toggle is an integer that is either the number 1 or 2. This determines if you add or substract the random time to your schedule time. If 1 it adds the random time and if 2 it subtracts the random time.
  • random_minute is a number randomly generated. It ultimately is utilized to calculate a minute that is added or subtracted to your scheduled time.
  • MinuteRange is the upper range or your random time in minutes. If you want your lights to come on at 7pm + or - (1 to 30 minutes) then enter in 30. Based on this figure your random minute can be anything between 1 and 30 minutes depending on what is generated from the random number generator.
  • InTime is user defined as the originally scheduled time (lets say 7pm).
  • OutTime is calculated by taking your InTime (7pm) and either subtracts or adds the random figure.
As an example, your lights normally come on at 7pm. With Premise it would always turn on at 7pm. By adding this script you can have it come on at variable times between 6:30 and 7:30 if you use a MinuteRange of 30.

Im sure there are easier ways to do this but this was my stab and it seems to work. First VBscript I've written. I still dont understand the "this." part but it works ;-)

#2 123



  • Registered
  • PipPipPipPip
  • 2170 posts
  • Location:Montreal, QC
  • Experience:average
  • Software:Premise
  • Hardware:Elk M1

Posted 30 March 2008 - 11:14 AM

"this" is a pointer to the currently-referenced object. Your script will work with whatever object uses it. You'll find the same nomenclature used in C++ and C#. I believe VB (.NET) uses "my" instead of "this".

Thanks for the Time Randomizer; I'll give it shot!

You can eliminate "this.toggle" if you constrain the Rnd function's range to be 0-1 and use the cbool function to translate the result into a true/false condition. cbool converts a positive number into "true" and zero is "false".

Here's the time randomizer using cbool and limiting the Rnd function's range to 0-1.

if sysevent.newVal then
	this.Random_Minute = (int((this.MinuteRange) * Rnd + 1))/24/60

	if cbool(int(2 * Rnd)) then
		this.OutTime = this.InTime + this.Random_Minute
		this.OutTime = this.InTime - this.Random_Minute
	end if
end if

Edited by 123, 31 March 2008 - 09:55 AM.

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users