time built-in variable - variables copy or reference

Discuss Lemur and share techniques.
Post Reply
blindekinder
Newbie
Posts: 3
Joined: 19 Sep 2017 10:04

time built-in variable - variables copy or reference

Post by blindekinder »

Hi!
I'm trying to deal with time for some applications: send a ping to a software every second, make some object blink. I tried something like that:

Code: Select all

decl timeA = floor(time) ;
while ( (floor(time)-timeA) < 1 ) { } //which should wait for 1sec 
maybe it's my arduino reflex...
but I noticed timeA and time are exactly the same, and (time - timeA) is alway 0, which means it use time by reference and not by copy.
How can I save 'time' value?
Or is there another way to manage time?
phase_change
Regular
Posts: 114
Joined: 31 May 2015 18:45
Location: Austin, TX

Re: time built-in variable - variables copy or reference

Post by phase_change »

I'm not sure if I understand what you're trying to do, but I think if you change it to

Code: Select all

decl timeA = floor(time) ;
while ( (time-timeA) > 0 ) { } 
or

Code: Select all

decl timeA = floor(time) ;
while ( (time-timeA) = 0 ) { } 
it will work.
The first one is more similar to your original code. While the values are greater than 0 it will do foobar. I don't think this would send out a ping every second though, but rather 999 times per second. The second one seems to me more like what you're trying to do. When the clock hits 0, so every 1000 ms, it will send out a ping.
Where I'm confused is by the reference vs. copy part. If it wasn't storing the time variable by reference, it seems to me like either floor(time)-timeA would also always = 0 or that timeA would always = 0. Either way, I don't see how this would work in your code?
Have you tried turning it off and on again?
Post Reply