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.
IndexProcessing DevelopmentLibraries,  Tool Development › Get started creating libraries
Pages: 1 2 
Get started creating libraries (Read 4284 times)
Re: Get started creating libraries
Reply #15 - Nov 27th, 2006, 12:01am
 
Please be patient with these dumb questions I’m a student and fairly new to all this. This is what I have now but I think I am doing something wrong in processing.

This is the code in processing

Code:


import pFem.*;

int a= FemCalc.Add(2,3);
print (a);

int b[][] = FemCalc.myFunc(1,1);
print (b[1][1]);


This is the java code.
Code:

package pFem;

public class FemCalc {

public static int arr[][];

public static int Add(int a, int b)
{
return(a+b);
}

public static int[][] myFunc(int a, int b)
{
arr[1][1] = a+b;
return arr;
}
}

Re: Get started creating libraries
Reply #16 - Nov 27th, 2006, 12:20am
 
Code:
package pFem;

public class FemCalc {

public static int arr[][];

public static int Add(int a, int b)
{
return(a+b);
}

public static int[][] myFunc(int a, int b)
{
/* -->> arr[1][1] = a+b; arr hasn't been initialised, you're accessing [1][1] when the array is null. Also, you probably want 0, not 1, since arrays are 0-index */
if(arr==null)
{
arr=new int[3][3];
}
arr[0][0]=a+b;
return arr;
}
}
Re: Get started creating libraries
Reply #17 - Nov 27th, 2006, 1:27am
 
awsome, ok I feel up to speed for now thank you all for your help.
Re: Get started creating libraries
Reply #18 - Nov 27th, 2006, 1:35am
 
How would I put an array back into the function from processing. for example.

this is the java

Code:


package pFem;

public class FemCalc {


public static int local[][];

public static int Add(int a, int b)
{
return(a+b);
}


public static int[][] localMatrix(int a[], int b)
{

/* -->> arr[1][1] = a+b; arr hasn't been initialised,
* you're accessing [1][1] when the array is null. Also,
* you probably want 0, not 1, since arrays are 0-index */

if(local==null)
{
local=new int[3][3];
}


local[0][0]=a[0]+b;
local[0][1]=a[1]+b+1;



return local;
}
}



This is what I am doing in processing.

Code:


import pFem.*;

int arr[] = {1,2};
int b[][] = FemCalc.myFunc(arr[],1);
print (b[0][0]);
print (b[0][1]);

Re: Get started creating libraries
Reply #19 - Nov 27th, 2006, 4:35pm
 
If it helps this is the error from processing

C:/DOCUME~1/Frank/LOCALS~1/Temp/build32044.tmp/Temporary_8810_1604.java:7:33:7:3
3: Syntax Error: Expression expected after this token

it works fine in eclipse

I would realy appreciate it if someone could help me with this.
Re: Get started creating libraries
Reply #20 - Nov 27th, 2006, 5:18pm
 
Code:
import pFem.*;

int arr[] = new int[]{1,2};
int b[][] = FemCalc.myFunc(arr[],1);
print (b[0][0]);
print (b[0][1]);

Re: Get started creating libraries
Reply #21 - Nov 27th, 2006, 8:16pm
 
that seems to be giving me the same error.
Re: Get started creating libraries
Reply #22 - Nov 27th, 2006, 8:54pm
 
Sorry yes, didn't see that error as well:

Code:
import pFem.*;

int arr[] = new int[]{1,2}; /* might be better writing this with "int[] arr" so you remember that the variable is called "arr" the [] just says it's an array, it's not part of the name.*/

int b[][] = FemCalc.myFunc(arr,1); // removed the [] processing knows it's an array, you only put the [] if you want to access part of it.

print (b[0][0]);
print (b[0][1]);
Pages: 1 2