Hi, I have an issue where I think I'm using symbols in a dictionary correctly, but I cannot access them after creation. I have the following code, with the important lines being 30 to 37:
import Toybox.Application; import Toybox.Lang; import Toybox.WatchUi; class countdownfieldApp extends Application.AppBase { hidden var _datafield; function initialize() { AppBase.initialize(); } // onStart() is called on application start up function onStart(state as Dictionary?) as Void { } // onStop() is called when your application is exiting function onStop(state as Dictionary?) as Void { } // Return the initial view of your application here function getInitialView() as Array<Views or InputDelegates>? { var settings = getSettings(); System.println("main seconds: " + settings.seconds); _datafield = new countdownfieldView(settings); return [ _datafield ] as Array<Views or InputDelegates>; } function getSettings() { var x = { :seconds=>Application.Properties.getValue("countdownSeconds"), :alertVibrate=>Application.Properties.getValue("alertVibrate") }; System.println("obj: " + x); System.println("get seconds: " + x.seconds); System.println("get seconds: " + x.alertVibrate); return x; } function onSettingsChanged() { var settings = getSettings(); _datafield.updateSettings(settings); } } function getApp() as countdownfieldApp { return Application.getApp() as countdownfieldApp; }
When I try to run this I get a compiler error:
BUILD: /Users/x/.p2/pool/plugins/org.eclipse.justj.openjdk.hotspot.jre.full.macosx.x86_64_16.0.2.v20210721-1149/jre/bin/java -Dfile.encoding=UTF-8 -Dapple.awt.UIElement=true -jar /Users/x/Library/Application Support/Garmin/ConnectIQ/Sdks/connectiq-sdk-mac-4.0.5-2021-08-10-29788b0dc/bin/monkeybrains.jar -o /Users/x/Documents/projects/garmin-countdown/bin/countdown-field.prg -w -y /Users/x/Documents/projects/garmin-countdown/developer_key -d fr245_sim -c 3.2.0 -f /Users/x/Documents/projects/garmin-countdown/monkey.jungle BUILD: ERROR: fr245: /Users/x/Documents/projects/garmin-countdown/source/countdownfieldApp.mc:37: Undefined symbol "alertVibrate" detected. BUILD: WARNING: The launcher icon (30x30) isn't compatible with the specified launcher icon size of the device 'fr245' (40x40). Image will be scaled to the target size. BUILD: Complete Aborting launch due to failed build.
If I comment out line 37, the alertVibrate then the compiler succeeds, but then fails at runtime:
obj: {symbol (8389344)=>58, symbol (29)=>true} Error: Symbol Not Found Error Details: Could not find symbol 'seconds' Stack: - getSettings() at /Users/x/Documents/projects/garmin-countdown/source/countdownfieldApp.mc:36 0x10000371 - getInitialView() at /Users/x/Documents/projects/garmin-countdown/source/countdownfieldApp.mc:22 0x10000291
As far as my understanding of the documentation, symbols are defined on their first use:
The Monkey C compiler will assign a new value when it encounters a new Symbol. This allows a developer to use Symbol objects as keys or constant values without explicitly declaring a constant
or enum
. While Symbol values are constant for a build, their values may change across builds. https://developer.garmin.com/connect-iq/api-docs/Toybox/Lang/Symbol.html
so I'm not sure why either of these errors are occurring. Anyone have an idea?