First time here? Check out the FAQ!

whileTrue:timeStep - How does this work?

0 votes

A day or two after my question about how can I evaluate a Capytalk expression every 10ms, whileTrue:timeStep came up as the Capytalk of the Day and I thought, aha! This could be a way of creating a repeating Capytalk expression of arbitrary frequency (without using tick). 

So I tried this in an STGC:

| counter |

counter := EventVariable new initialValue: 0.

1 whileTrue: (counter <~ (counter + 1)) timeStep: !Duration s

This doesn't work. In fact I don't even get a !Duration fader in the VCS. I don't understand why "1" is a suitable receiver for a Capytalk message like "bpm:" but not for "whileTrue:timeStep". Is there a way of knowing which Capytalk messages work for numbers and which only work on EventValue expressions?

But the plot thickened when I tried something more "normal"

| counter |

counter := EventVariable new initialValue: 0.

!Gate whileTrue: (counter <~ (counter + 1)) timeStep: 1 s

When I press the !Gate button in the VCS the STGC counts up in rapid spurts. Every time I click the button the counter leaps forward by a large number as if the expression argument of whileTrue: is being repeatedly evaluated at Capytalk rate while the button is down. The help for whileTrue:timeStep seemed to suggest to me that the value of !Gate would be tested only once per timeStep duration. 

So I tried this:

| counter |

counter := EventVariable new initialValue: 0.

!Gate switchedOn whileTrue: (counter <~ (counter + 1)) timeStep: 1 s


The behaviour of this is the counter increments by one every time I click the !Gate button irrespective of what the timeStep duration is set to. If I set the duration to 10 s and click really fast it still increments really fast. 

I'm not sure what the timeStep: argument does and how I'm supposed to use is. 


asked May 24, 2019 in Capytalk & Smalltalk by alan-jackson (Virtuoso) (15,740 points)
Fixed. Thanks!

Please log in or register to answer this question.