Stopping a Timer seems not to work

Hi

I’m playing around with timers. Nothing “real” for not, but just to learn how to use them.
Starting a timer does work already, stopping it however doesn’t.


	property currentValue : 0
	property myTimer : class "NSTimer"
	
	on start_(sender)
		myTimer's scheduledTimerWithTimeInterval_target_selector_userInfo_repeats_(0.2, me, "einsplus:", missing value, true)
		
	end start_
	
	on einsplus_(sender)
		set currentValue to currentValue + 1
		toggler's setTitle_(currentValue)
	end einsplus_
	
	
	on countstop_(sender)
		myTimer's invalidate()
	end einsminus_

All this test sample does is count a value.
As said, when you hit the start-button (binded with start_) the timer kicks in and counts.
but when you hit the stop button (binded with countstop_) nothing happens.

I also tried a few other things to stop the timer like:



		myTimer's invalidate()
		myTimer's invalidate(missing value)
		myTimer's invalidate(true)
		myTimer's invalidate_()
		myTimer's invalidate_(missing value)
		myTimer's invalidate_(true)

Non of these works however.

According the another post however, this should work:
http://macscripter.net/viewtopic.php?id=31692
http://macscripter.net/viewtopic.php?id=31488

It doesn’t however :slight_smile:
Any idea why not?

change

property myTimer: class "NSTimer"

to

property myTimer : missing value

and use


myTimer's |invalidate|()

Now that’s strange.

When I “pipe” the method invalidate, the pipes get removed immediately after saving the document.
When I pipe another method (e.g. setState_), the pipes keep there.

Why is that, why does Xcode strip away the Pipes?

edit:
I figured it out.
Initiated the Timer like this:

		set myTimer to current application's NSTimer's scheduledTimerWithTimeInterval_target_selector_userInfo_repeats_(0.2, me, "einsplus:", missing value, true)

And now it’s “invalidate”-able :slight_smile:
Thanks a lot.

I think the Pipes go away around the invalidate because they aren’t needed anyway