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.
@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)
@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 ))
Best AnswerI did it, but tval = [object object] is this right? if so how do i extract the settings item i want?
Best Answer
@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)