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 & HelpPrograms › using variables in PApplet.size
Page Index Toggle Pages: 1
using variables in PApplet.size (Read 428 times)
using variables in PApplet.size
Jan 26th, 2009, 3:11am
 
from PApplet.size docs:

"Do not use variables as the parameters to size() command, because it will cause problems when exporting your sketch. When variables are used, the dimensions of your sketch cannot be determined during export. Instead, employ numeric values in the size() statement, and then use the built-in width and height variables inside your program when you need the dimensions of the display window are needed."

why exactly is this?  is there a way (hacky or not) to get around this?

my goal is to be able to set my application size via an xml file.
Re: using variables in PApplet.size
Reply #1 - Jan 26th, 2009, 11:50am
 
I think the main reason is that Processing with use the numbers in the size() call to compute the size of the applet when exporting the sketch (mmm, reading the quoted doc, that's exactly what is stated...). There might be other reasons as well. Note also size() should be the first instruction of setup(), there can be side effects on code before it.

Note you can resize the sketch later, using frame.setSize(w, h);

Re: using variables in PApplet.size
Reply #2 - Jan 26th, 2009, 7:07pm
 
from an in-the-know friend of mine:

Quote:
its b/c the exporter does a regular expression parse of that line to determine
the height and width of the applet/app its is creating


hm...
Re: using variables in PApplet.size
Reply #3 - Jan 26th, 2009, 7:09pm
 
oh, and resizing the sketch later isn't good for me, because a lot of my initialization code needs to know width/height up-front.  i can rewrite that code, of course, to look at some other variable, so that's not the biggest issue.

another issue is that running in present mode centers the app in the screen based on its size as set in startup.  another way around this problem would be to find out how to recenter the app after setup() (or main() or whatever does the centering...haven't had time to dig into PApplet to figure out where/how that happens yet).
Re: using variables in PApplet.size
Reply #4 - Jan 26th, 2009, 11:59pm
 
There might be a workaround (untested): the not so known void init() function is called before setup(). Perhaps you can use it to load and parse your XML file and compute the size.
You will avoid the side effects (like double running of instructions between start of setup() and size() call) but will loose the computation of the size of the applet, which isn't much a problem if you don't use it as an applet (or know how to manually set it).
Re: using variables in PApplet.size
Reply #5 - Jan 27th, 2009, 8:26pm
 
actually, i'm not having any trouble parsing my XML before size() in setup, though it is possible that it's being called twice (haven't looked into that, and that would not affect my program).  thanks for the init() tip, though.

still don't have a way to use my xml config to set the size of the applet tho.  if i figure anything out, will post here.
Page Index Toggle Pages: 1