I'm just beginning to play around with HaikuHelper scripting and can't seem to get access to the fields in the object returned by helper.weatherForLocation(). I've got plenty of experience in Java, but this is my first use of JavaScript. Any explanation of what I'm doing wrong would be much appreciated.
Here's the script I'm using:
function onSyncStart(forced, timestamp) {
runTest1();
}
function runTest1(){
alert('test2');
if(controller.preferences.weatherLocation != null) {
var weather = helper.weatherForLocation(controller.preferences.weatherLocation);
if (weather != null){
alert(weather);
alert(weather.current);
} else {
alert('weather is null');
}
}
}
This generates three alert pop-ups. The first says 'test2'. The second has a dump of the weather object in it. Like this:
{
current = {
code = 116;
conditions = "Partly Cloudy ";
humidity = 79;
location = 78704;
temperature = 79;
};
forecast = (
{
code = 293;
conditions = "Patchy light rain";
day = Wed;
high = 81;
low = 71;
precip = "11.7";
},
{
code = 113;
conditions = Sunny;
day = Thu;
high = 78;
low = 56;
precip = "30.3";
},
{
code = 113;
conditions = Sunny;
day = Fri;
high = 80;
low = 55;
precip = "0.0";
},
{
code = 113;
conditions = Sunny;
day = Sat;
high = 71;
low = 47;
precip = "0.0";
},
{
code = 116;
conditions = "Partly Cloudy ";
day = Sun;
high = 64;
low = 55;
precip = "0.7";
}
);
}
The third just says 'undefined'. I expect that I should be able to access the fields in weather using syntax like weather.current.location, but this causes the script to throw an exception since weather.current is apparently undefined even though I can see it in that second alert.
How have I screwed this up? And what's the preferred method for accesing those members?
Thanks,
- dave
Here's the script I'm using:
function onSyncStart(forced, timestamp) {
runTest1();
}
function runTest1(){
alert('test2');
if(controller.preferences.weatherLocation != null) {
var weather = helper.weatherForLocation(controller.preferences.weatherLocation);
if (weather != null){
alert(weather);
alert(weather.current);
} else {
alert('weather is null');
}
}
}
This generates three alert pop-ups. The first says 'test2'. The second has a dump of the weather object in it. Like this:
{
current = {
code = 116;
conditions = "Partly Cloudy ";
humidity = 79;
location = 78704;
temperature = 79;
};
forecast = (
{
code = 293;
conditions = "Patchy light rain";
day = Wed;
high = 81;
low = 71;
precip = "11.7";
},
{
code = 113;
conditions = Sunny;
day = Thu;
high = 78;
low = 56;
precip = "30.3";
},
{
code = 113;
conditions = Sunny;
day = Fri;
high = 80;
low = 55;
precip = "0.0";
},
{
code = 113;
conditions = Sunny;
day = Sat;
high = 71;
low = 47;
precip = "0.0";
},
{
code = 116;
conditions = "Partly Cloudy ";
day = Sun;
high = 64;
low = 55;
precip = "0.7";
}
);
}
The third just says 'undefined'. I expect that I should be able to access the fields in weather using syntax like weather.current.location, but this causes the script to throw an exception since weather.current is apparently undefined even though I can see it in that second alert.
How have I screwed this up? And what's the preferred method for accesing those members?
Thanks,
- dave