We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hi! I am trying to get a function return a string so I can check some things. Anyway, it's better to show the code:
import com.onformative.yahooweather.*;
YahooWeather weather;
int updateIntervallMillis = 30000;
weather = new YahooWeather(this, 56594508, "c", updateIntervallMillis);
void setup() {
size(200,200);
frameRate(1);
}
String weatherCondition;
void draw() {
weather.update();
println(weatherCondition);
}
String weather.getWeatherCondition() {
return weatherCondition;
}
So, after the function getWeatherCondition() returns the string, I need to check if it says that is saying "Light Rain", or "Cloudy" or any other things to trigger some events after this. It says that "expecting EOF,'weather' found" but when I put the "weather = new..." line in setup it still doesn't work. It says that I get null.
Answers
line 4 should be in setup()
based on https://github.com/onformative/YahooWeather/blob/master/src/com/onformative/yahooweather/processing15/YahooWeather.java
your function should be more like
where weather is your YahooWeather class, getWeatherCondition() is an accessor within it allowing you to read the member. but, you'll notice, that that method is pretty ridiculous as it stands.
Another way to do it then?
I always prefer the order
imports
consts
global vars
setup()
draw()
Input funcs
other funcs
classes
you mixed funcs and global vars.
here
but that's what i said! 8)
a method containing a single line, just returning a value from another method, usually isn't worth the overhead of calling it. so line 17 (of chrisir's code) could just be
and you could delete lines 24-26.
i'd've left the frameRate in there - no need to update 60 times a second when the data's only changing every 30 seconds (and maybe not even then - how often does weather change?)
yeah, absolutely what you've said, I just put it together
;-)
in your code, koogs, in line 2 the ( ) was missing
in his code line 13 was a mess
so I wanted to try it...
;-)
ha, thanks, didn't spot those
As some legends say, Java VM can later inline such simple get()/set() calls! :-$
Although if it's just 1 or 2 places that happen to call it, I don't bother! :-))
Anyways, I've made a remix too. Check it out: =P~
P.S.: UNTESTED! :@)
Why doesn't this work then? It doesn't throw an error. It just doesn't write anything... What di I do wrong? This is Chrisir's example.
http://processing.org/reference/String_equals_.html
yeah, == doesn't work with String
you need to say
if (getWeatherCondition().equals("Sunny")) {
(not tested)
It's a pain...
;-)