# Getting value of clock [duplicate]

This question already has an answer here:

I have the following code:

a = Dynamic[Floor[Clock[2]]] (*So this basically alternates between 0 and 1*)
If[a==1, Print["true"]]


But this doesn't work, it instead prints the following If[a==0, Print["true"]] and then changes to If[a==1, Print["true"]] and then back.

How can I get the value from the clock?

-
–  Mr.Wizard Apr 8 '13 at 10:25

## marked as duplicate by Mr.Wizard♦Apr 8 '13 at 10:22

Well, looking at the other answers, I am not sure if I correctly understand what you want. But I'll give it a go:

a = Dynamic[Floor[Clock[2]]](*same thing*)
Dynamic[If[Setting@a == 1, "true", "false"]]


Does this yield what you wanted? The problem in your case is, that a is no "plain" integer, see FullForm[a]. Thus, the test a==1 is not executing. Using Setting lets you retrieve the value of a Dynamic var, see e.g. here: Dynamic Values

-
Thank you very much, this works! –  user1626227 Apr 8 '13 at 8:11
a = Dynamic[Floor[Clock[2]]] (*So this basically alternates between 0 and 1*)If[a === 1, Print["true"]]