We are about to switch to a new forum software. Until then we have removed the registration on this forum.
How to call thread("functionName") in draw() with when the function is in a class in other tab? if I put the function in the main class, it has no problem. If I put them in a class in other tab, I get "There is no public functionName() method in the class xxxxxx" msg.
Answers
Function thread() can only call PApplet methods of the same instance.
It uses reflection internally and can't see methods from other classes.
And to answer your next question, you could manually create a
Thread
instance and call whatever function you want from itsrun()
function.However, you should be really absolutely positively sure that you need to use threading before you do this.
Thanks guys, but let me make sure I fully understand. Here is the code example.
Are you saying I can't put the loadData() in other class when I try to do OOP?
A link relevant to this discussion:
https://forum.processing.org/two/discussion/comment/73362/#Comment_73362
Kf
Yes. The loading class should either implement the Runnable interface or extend the Thread clas.
http://query.YahooApis.com/v1/public/yql?format=xml&q=select+*+from+weather.forecast+where+woeid=1118370+and+u='C'
Thanks guys. GoToLoop, code not working?
Unfortunately not! The YahooApis.com returns "Bad Gateway 502". :(
Seems like they don't like generic programs accessing their query? :-/
Unless they can somehow pretend they're a browser? :ar!
I'm not sure I understand your question. But if you move the
loadData()
function, then you'll have to use the approach I outlined above: using aThread
to run it yourself instead of relying on thethread()
function. It's not a ton of syntax:But like I said, using threading (either by calling the
thread()
function or by creating your ownThread
) introduces a ton of complexity, so make sure you really understand what's going on here.For example, since you're setting
txt
in one thread (and you're doing it in a way that takes mutliple steps) and drawing it in another, you could run into the case wheretxt
is not fully set while you're drawing it. These types of bugs can be very hard to track down.Good to know!
Still, @KevinWorkman 's basic statement that "using threading ... introduces a ton of complexity" remains good advice. And many threading bugs are very hard to track down. Processing attempts to hide some of that complexity by wrapping asynchronous behavior itself. Those wrappings are primitive -- thread() and loadData() don't support calling class methods in ways that are intuitive when trying to build an OOP pattern.