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 › param() function
Page Index Toggle Pages: 1
param() function (Read 455 times)
param() function
Sep 25th, 2008, 2:31am
 
Hello,

I am having difficulty trying to use the the param function.

I export the sketch and it creates the applet folder for me. when I double click on the index.html file and it opens locally, I get an error message in the applet area and when I click for more details, it tells me that:
param() only works inside a web browser

but I am in a web browser

the code in my index.html file to call the applet is:
<applet code="BrickTowerParam" archive="BrickTowerParam.jar"
width="200" height="200" mayscript="true">
<param name="bl" VALUE="18">
</applet>

(I deleted the autogenerated applet code and replaced it with code that resembles the example)

and the line in my sketch is:
float brickLayers = float(param("bl"));

I am getting the error in both chrome and ie. I downloaded the latest jre 1.6.0_10.

would appreciate any help anyone can offer.

thanks!

Re: param() function
Reply #1 - Sep 25th, 2008, 12:44pm
 
My guess: param() doesn't work with an URL like file:///E:/www/Foo.html which points to local file system, not to a real Web server. You have such URL if you drag'n'drop the file to the browser (or use Open menu).

Solutions:
- Install a local Web server, and use http://localhost/Foo.html (supposing the root directory of the server points to E:\www -- Windows style path, applies to other systems, of course).
- Upload your files to a real (on the Net) Web server. Less fuzz (if you have access to such server), but a bit more annoying for quick update/test cycle.
Re: param() function
Reply #2 - Sep 25th, 2008, 4:19pm
 
Thanks for the reply, but alas, that was not the solution.

I am developing in xampp at my present gig, so I tried opening it locally

http://localhost/paramtest

and got the same error. thinking it may be a strange xampp problem, I tried your next suggestion and uploaded it to my personal website

http://www.ronrosenman.com/sandbox/paramtest/

and am still getting the same error.

very strange..
Re: param() function
Reply #3 - Sep 26th, 2008, 2:21pm
 
you can't use param() (or even most api functions) outside a function like that. it can only be run when called from setup() or draw(), otherwise the applet hasn't initialized properly, so it hasn't yet found the web browser it's connected to. for best results, use:

void setup() {
 // the size() method here

 // next your param() lines here

 // .. everything else
}
Re: param() function
Reply #4 - Oct 1st, 2008, 3:48pm
 
oh man, that was an easy fix. makes total sense.

thanks fry

r
Page Index Toggle Pages: 1