Hello,
i recently started developing my first app for Garmin devices. I have an application where I want to change the interval of timers based on a state I get via REST API. So far so good.
I created my own Timer class including the Toybox.Timer and adding a getTime() Method. When I start a Timer, the time set will be stored in a privat variable I then can acces with this getter function.
This is the class:
class myTimer { hidden var _timer = new Timer.Timer();; hidden var _time; public function start(callback, time as Lang.Number, repeat as Lang.Boolean) as Void { _timer.start(callback, time , repeat); _time = time; } public function stop() as Void { _timer.stop(); } public function getTime() as Lang.Number { return _time; } }
Everything works fine. But theres one problem I encounter and find nothing about in the API docs or the Reference guide nor the sample projects. Looking at the start function:
public function start(callback, time as Lang.Number, repeat as Lang.Boolean) as Void { _timer.start(callback, time , repeat); _time = time; }
I can tell the compiler I expect time to be a Lang.Number, and repeat a Lang.Boolean. but when I want callback to be a "callback as Lang.Method() as Void" i get a compile error. In the API docs its written exactly like this.
https://developer.garmin.com/connect-iq/api-docs/Toybox/Timer/Timer.html#start-instance_function
Error i get:
ERROR: instinct2: C:\Users\XXX\Documents\software\YYY\ZZZ\source\myTimer.mc:9,42: mismatched input '.' expecting {')', ','} ERROR: instinct2: C:\Users\XXX\Documents\software\YYY\ZZZ\source\myTimer.mc:21: extraneous input '}' expecting {<EOF>, 'class', 'module', 'using', 'import', 'alias', 'typedef', 'public', 'const', 'native', 'var', 'enum', 'function', '('}