05-24-2020 02:02
05-24-2020 02:02
My clock face has a Select options settings where the user picks out of a couple of options.
Currently its using this line to retrieve the selected option: settings["bottomRight"].values[0].value
where bottom right is the settingskey.
The problem is that whenever I sideload the clock face to my watch it doesn't recognize it and returns an error. " '0' is not defined ". But will take the command: settings["bottomRight"].
When I've changed it and ran it, it works, if i run it again it won't work and require the original command.
Please help.
Answered! Go to the Best Answer.
05-25-2020 11:14 - edited 05-25-2020 11:17
05-25-2020 11:14 - edited 05-25-2020 11:17
@mzamo wrote:I did it, but tval = [object object] is this right? if so how do i extract the settings item i want?
Generally if you want to log an object, you need to loop through it
let tVar = JSON.parse(evt.newValue)
for (let x in tVar){
console.log(' TYPE: ' + typeof (tVar[x]) + ' NAME: ' + x )
if (typeof (tVar[x]) == 'object') console.log(tVar[x])
else console.log('VALUE: ' + tVar[x])
}
After you figure out what's in it, it's a lot easier to address the contents. In the case of selects, the selected value is:
console.log(tVar.values[0].value)
05-24-2020 13:09
05-24-2020 13:09
Could you be trying to access the setting before it's been set? Until a user actually interacts with a setting, it will be undefined unless you define a default for it in code.
05-24-2020 17:26 - edited 05-24-2020 17:39
05-24-2020 17:26 - edited 05-24-2020 17:39
@mzamo wrote:My clock face has a Select options settings where the user picks out of a couple of options.
Currently its using this line to retrieve the selected option: settings["bottomRight"].values[0].value
where bottom right is the settingskey.
The problem is that whenever I sideload the clock face to my watch it doesn't recognize it and returns an error. " '0' is not defined ". But will take the command: settings["bottomRight"].
When I've changed it and ran it, it works, if i run it again it won't work and require the original command.
Please help.
I had roughly the same problem; toggles would work, colors selects would select, but selects always failed when the watchface restarted. It's hardly noticeable with the simulator, but people with actual watches expect their settings to persist.
settingsStorage works better when the values are stringified, otherwise the getItem function doesn't return the original object correctly.
settingsStorage.setItem( tKey , JSON.stringify(newValue) )
var tVal = JSON.parse(settingsStorage.getItem( tKey ))
05-25-2020 04:11
05-25-2020 04:11
I had that issue before, but it seems to have solved by using the hasOwnProperty() method
05-25-2020 05:15
05-25-2020 05:15
I did it, but tval = [object object] is this right? if so how do i extract the settings item i want?
05-25-2020 11:14 - edited 05-25-2020 11:17
05-25-2020 11:14 - edited 05-25-2020 11:17
@mzamo wrote:I did it, but tval = [object object] is this right? if so how do i extract the settings item i want?
Generally if you want to log an object, you need to loop through it
let tVar = JSON.parse(evt.newValue)
for (let x in tVar){
console.log(' TYPE: ' + typeof (tVar[x]) + ' NAME: ' + x )
if (typeof (tVar[x]) == 'object') console.log(tVar[x])
else console.log('VALUE: ' + tVar[x])
}
After you figure out what's in it, it's a lot easier to address the contents. In the case of selects, the selected value is:
console.log(tVar.values[0].value)