returning results of a method 2x

Hi.

I have an applet that calls a method twice in the init() . Each time the method is called, two different boolean parameters are passed to it. At the end of the method is a return statement which returns the results of an integer multi-variable called grid. However for some reason Java doesn't seem to call the method twice, but instead assigns the second call from memory. Can someone please let me know how to fix this problem.

//Declare variables and Data Types

int[][][] grid =newint[16][16][3];

int[][][] player =newint[16][16][3];

int[][][] computer =newint[16][16][3];

//setUpPlayer()

publicint[][][] setUpPlayer(boolean ispc){

// ... Code That Generates the grid ...

return grid;

}

//Init()

publicvoid init(){

player = setUpPlayer(false);

computer = setUpPlayer(true);

}

So why are the computer and player objects the same. That is, why is player[16][16][3] = computer[16][16][3] = grid[16][16][3] ? Shouldn't the return statement be different every time the setUpPlayer() is called ?

Please help.

[1969 byte] By [newjack2000] at [2007-9-26 2:03:10]
# 1
Since your setupPlayer returns grid, no matter how many times you call it it will return grid - unless you have another variable called grid in the method, which will take precedence over the class variable. It appears that you do not have one, so it will always return grid
shirish_wagh at 2007-6-29 8:45:34 > top of Java-index,Archived Forums,Java Programming...
# 2
Thanks for the clarification. Sometimes the answer is right under your nose. I moved the grid variable from the global to the local setUpPlayer method. Thanks again and you get 2 points.
newjack2000 at 2007-6-29 8:45:34 > top of Java-index,Archived Forums,Java Programming...