Timer Using Now()

Goal: Use the now() expression function to get the current time and repeat every 5 seconds.
Ex. now, now+5s, now+10s... etc.

Issue: Using now(5000) does not run instantly, rather waits 5 seconds as it is intended to.
Ex. now+5s, now+10s, now+15s

Are there any easy suggestions to get around this issue?

This is a little strange. Can you explain what is the real problem you are trying to solve?

2 Likes

I need data on a popup to refresh every 5 seconds and do not want the wrong information showing for the first 5 seconds the popup is open.

What data do you have on this popup? Just a timer? A table of data? How are you getting the data to this popup?

1 Like
  • In Project Browser, select the root of your popup view.
  • In Perspective Property Editor scroll down to CUSTOM.
  • Create a new custom property startTime.
    • Create an expression binding on startTime with the expression, now(0). This will fire once when the popup opens and save the current timestamp in the custom property.
  • Create a second tag, timeout.
    • Add an expression binding,
      (now(1000) - {this.custom.startTime}) > 5000
      This will evaluate every 1000 ms and will return true when the popup has been open for 5000 ms.
  • Right-click on custom.timeout and select Edit Change Script. Add the script,
def valueChanged(self, previousValue, currentValue, origin, missedEvents):
	if currentValue.value:
		self.custom.timerStart = system.date.now()

This will update timerStart resetting timeout allowing the sequence to repeat.

1 Like

Or you could use an expression structure binding with one of the expressions being your timer. ( now(5000) ).

Thanks Transistor and bwirth for the responses.

This seemed to be the simplest solution:
Use an expression structure binding with two parameters, one set to now(0) and the other now(5000). Ensure to set 'Wait On All' to False on the binding.
Then add an expression transform...

if(
	{value}['time'] - {value}['startTime'] < 5000, 
	{value}['startTime'], 
	{value}['time']
)

how about toDate(max(now(0), now(5000))) ?

note that in my tests, now(5000) does give a value immediately, so I get the same results:
t0, t0+5, t0+10, etc...

1 Like