This site requires JavaScript, please enable it in your browser!
Greenfoot back
KenCo
KenCo wrote ...

2014/8/30

Re Universal Array

KenCo KenCo

2014/8/30

#
I am happy that this can be achieved and would thank erdelf and danpost for their immediate response but may I be more specific. The subclass of World is called Reckon3. I have now defined the array in Reckon3 thus : public int grid = new int ; How would the code look in 'Marker' which is my subclass of Actor. To see it written in this way is the only way this befuddled old brain will understand it. Thank you once again.
danpost danpost

2014/8/30

#
KenCo wrote...
The subclass of World is called Reckon3. I have now defined the array in Reckon3 thus : public int grid = new int ; How would the code look in 'Marker' which is my subclass of Actor.
Please be more specific as to what you want. 'How would the code look' is quite vague. Do you want to move the array out of the Reckon3 class and into the Marker class? or what?
KenCo KenCo

2014/8/30

#
danpost thank you for persisting with this query. As you suggest I want to move the array 'grid' from Reckon3 into the Marker class to enable elements of the array 'grid' to be used and amended in this class and it's 4 subclasses. I ask because I am unable to understand this part of greenfoot coding as this is my first attempt to create a scenario and my first use of java.
danpost danpost

2014/8/30

#
Then just move it into the Marker class where it will be accessible to it and all its subclasses. Make the array a 'static' one so the objects created from its subclasses all share the same array and are not given individual arrays to work with:
public static int[][] grid = new int[81][5];
If you only want the array accessible to the Marker class and its subclasses (that is, you do not want any other classes to have access), then use:
protected static int[][] grid = new int[81][5];
You need to login to post a reply.