We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSyntax Questions › disabling save when running as applets
Page Index Toggle Pages: 1
disabling save when running as applets (Read 715 times)
disabling save when running as applets
Oct 6th, 2009, 3:24pm
 
I am working on a set of sketches that need to run locally as well as an applet. When running from within the Processing environment, I need to use save() for screenshots.

But when running inside an applet, I need to disable the save otherwise the applet crashes.

I could certainly have two copies, but it is really too cumbersome at this point.

Is there any ways to detect whether I am running as an applet?
Or do you have any other idea for me to keep the same code, but enable/disable save()?

Thanks
Re: disabling save when running as applets
Reply #1 - Oct 6th, 2009, 10:46pm
 
There is a variable built in to test if your app is running in a web browser: 'online'.
Usage:

if (!online) {
 //save pic
}
Re: disabling save when running as applets
Reply #2 - Oct 7th, 2009, 5:21am
 
I did that, but it crashes anyway. Here is my trivial sketch.

Quote:
ellipse(50,50,25,25);

// code used to capture screenshots
if(!online) save("sketch.png");




Any idea on how to make this work? I do not really understand why it would break, but it does.

-x
Re: disabling save when running as applets
Reply #3 - Oct 7th, 2009, 8:23am
 
It works for me.
Tested also with:
if (!online) println("Not on line"); else println("On line");
(result can be seen in the Java console).
Don't forget to remove the applet from the cache when updating it.
Page Index Toggle Pages: 1