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 › Will not work when String is passed w/ Param.
Page Index Toggle Pages: 1
Will not work when String is passed w/ Param. (Read 451 times)
Will not work when String is passed w/ Param.
May 12th, 2008, 3:42am
 
This simple code that i wrote works when the text is hard coded, but then will not work when the text is a String passed in w/ Param().

Can anyone help?  Thanks!

The code below works when viewed in browsers.  I included the Param code, but commented it out.

void setup() {
size(600, 400);
background(255);
frameRate(1);
PFont myFont;
myFont = createFont("CourierNew36.vlw", 50);
textFont(myFont);
fill(0);
}

//String lines = param ("tenwords");
String lines = "ten,words,in,a,row,that,may,not,make,sense";

String words[] = split(lines, ",");

void draw() {
for (int i=0; i < words.length; i++) {
 println(words[i]);
 
 float r = random(0, 100);
 rotate(r);

 float ts = random(12, 125);
 textSize(ts);
 
 float p = random(0, 400);
 float z = random(0, 600);
 text(words[i], p, z);
}
}

void keyPressed() {
 exit();
}
Re: Will not work when String is passed w/ Param.
Reply #1 - May 12th, 2008, 4:10am
 
you can try processing's online variable. it returns true when running as an applet in your browser and false when running from processing.

Code:

String lines;

void setup() {
// your setup code here
if(online==true) {
lines = param ("tenwords");
} else {
lines = "ten,words,in,a,row,that,may,not,make,sense";
}
}


Re: Will not work when String is passed w/ Param.
Reply #2 - May 13th, 2008, 7:00pm
 
What is the HTML code you use to pass the param to the applet?
Re: Will not work when String is passed w/ Param.
Reply #3 - May 19th, 2008, 6:33am
 
I am not sure what you mean by this, so maybe I am not even passing the param to the applet, but here is the code that is generated when I export the Processing.

<object classid="java:display.class"
           


type="application/x-java-applet"
           


archive="display.jar"
           


width="600" height="400"
           


standby="Loading Processing software..." >
           







<param name="archive" value="display.jar" />









<param name="mayscript" value="true" />





<param name="scriptable" value="true" />









<param name="image" value="loading.gif" />





<param name="boxmessage" value="Loading Processing software..." />





<param name="boxbgcolor" value="#FFFFFF" />









<param name="tenwords" value="$thePoem" />



<!--<![endif]-->








<object classid="clsid:8AD9C840-044E-11D1-B3E9-00805F499D93"






codebase="http://java.sun.com/update/1.4.2/jinstall-1_4_2_12-windows-i586.cab"






width="600" height="400"






standby="Loading Processing software..."  >











<param name="code" value="display" />





<param name="archive" value="display.jar" />










<param name="mayscript" value="true" />





<param name="scriptable" value="true" />










<param name="image" value="loading.gif" />





<param name="boxmessage" value="Loading Processing software..." />





<param name="boxbgcolor" value="#FFFFFF" />










<param name="tenwords" value="$thePoem" />










<p>






<strong>







This browser does not have a Java Plug-in.







<br />







<a href="http://java.sun.com/products/plugin/downloads/index.html" title="Download Java Plug-in">








Get the latest Java Plug-in here.







</a>






</strong>





</p>








</object>







<!--[if !IE]> -->




</object>
Re: Will not work when String is passed w/ Param.
Reply #4 - May 19th, 2008, 2:28pm
 
You have <param name="tenwords" value="$thePoem" />  so indeed the parameter is there.
Do you have this code in a PHP program? If not, you will have only one word, "$thePoem".
And well, I recall having seen that one should avoid code outside of setup() when this function is there.
So keep line and words declarations outside, but move their initialization in setup().
Page Index Toggle Pages: 1