Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old May 23rd, 2006, 8:17 PM   #1
Eric the Red
Hobbyist Programmer
 
Eric the Red's Avatar
 
Join Date: Feb 2006
Posts: 214
Rep Power: 0 Eric the Red is an unknown quantity at this point
1 class, 1 problem = 1 big headache

So i'm working on this big project in java (tetris) and i came across this error which could effect my entire program. Anyone who has a pretty good understanding of java's classes (simple stuff i would think) should continue reading.

I've narrowed down my code just to show the main problem causing the error.

        class Tetris
        { 
            
            public SmallBox smBox [] [];

            public Tetris ()
            {
                SmallBox smBox [] [] = new SmallBox [xMax] [yMax];
            }

            public void dltLine (int y)
            {
             // temp removed
            }

            public void movePiece (int x)
            {
            // temp removed
            }
           
        }

        class Piece
        {

            public SmallBox smPiece [] [];
            public SmallBox smBox [] [];

            public Piece ()
            {
                SmallBox smPiece [] [] = new SmallBox [xPiece] [yPiece];

                for (int y = 0 ; y < 4 ; y++)
                {
                    //smPiece [x] [y] = -10;
                }
            }


            public void extractPiece ()   // this is used to take the piece from 'The Grid' and assign it back into the 'pieceGrid' (so that we can work with it)
            {
                boolean tempPiece = false;
                int tempX1 = 0, tempY1 = 0; // used to mark the first tetris block found on the main grid.
                for (int y = 0 ; y < yMax ; y++)
                {
                    for (int x = 0 ; x < xMax ; x++)
                    {
                        if (smBox [x] [y].getActive = true) // once we find a moving block on the grid that belongs to piece.. we mark it.
                        {
                            tempX1 = x; // marks x cord of moving block
                            tempY1 = y; // marks y cord of moving block

                            SearchStart:
                            for (int startY = tempY1 ; startY < yMax ; startY++) // runs through the vertical part of the main grid to top of grid
                            {
                                if (smBox [x] [startY].getActice  = true) // if the piece above the marked one is there we move to the left on the x-axis
                                {
                                    break SearchStart;
                                }
                            }
                        }
                    }
                }
            }
        }

The orange font is where the error occurs. Apparently, i can't use the
"smbox[][]" array from the tetris class. So how am I supposted to use it then?

One other thing, is it okay to use smBox[][] in both classes this way? or should i pass it in from main() to the class?
__________________
Death smiles at us all. All a man can do is smile back.
Eric the Red is offline   Reply With Quote
Old May 23rd, 2006, 8:22 PM   #2
Jimbo
Battle Programmer
 
Jimbo's Avatar
 
Join Date: Feb 2006
Location: Bellevue, WA, USA
Posts: 762
Rep Power: 3 Jimbo is on a distinguished road
Didn't really read through the code, mainly just the hightlighted line. Did you copy this straight from your file? Because you're using = instead of == in the if. This also happens 7 lines earlier. Also, the highlighted getActive is spelled wrong...
Jimbo is offline   Reply With Quote
Old May 23rd, 2006, 8:30 PM   #3
Eric the Red
Hobbyist Programmer
 
Eric the Red's Avatar
 
Join Date: Feb 2006
Posts: 214
Rep Power: 0 Eric the Red is an unknown quantity at this point
Quote:
Originally Posted by Jimbo
Didn't really read through the code, mainly just the hightlighted line. Did you copy this straight from your file? Because you're using = instead of == in the if. This also happens 7 lines earlier. Also, the highlighted getActive is spelled wrong...
Lol.. sorry about that, i must have put that in there when trying to fix the problem. Nevertheless, the problem is still there after your tips, thx for pointing that out.
__________________
Death smiles at us all. All a man can do is smile back.
Eric the Red is offline   Reply With Quote
Old May 23rd, 2006, 8:45 PM   #4
andro
Professional Programmer
 
Join Date: Oct 2005
Location: California
Posts: 309
Rep Power: 3 andro is on a distinguished road
Send a message via AIM to andro
You also have another line above that one using '=' instead of '==', so if that line works then this one should too. Maybe if you post ALL of your code we can take a look at it for you.
andro is offline   Reply With Quote
Old May 23rd, 2006, 10:44 PM   #5
Eric the Red
Hobbyist Programmer
 
Eric the Red's Avatar
 
Join Date: Feb 2006
Posts: 214
Rep Power: 0 Eric the Red is an unknown quantity at this point
Yes.. as I said, "the problem is still there after your tips", meaning that I looked into the matter. The statements are now "=="
__________________
Death smiles at us all. All a man can do is smile back.
Eric the Red is offline   Reply With Quote
Old May 23rd, 2006, 10:52 PM   #6
King
Professional Programmer
 
King's Avatar
 
Join Date: Jan 2006
Location: Ontario, Canada
Posts: 376
Rep Power: 0 King is an unknown quantity at this point
To use a variable method from another class, you will have to instantiate an object of that class to access it. You should also make smbox[][] private, and use a getter method to access it.
__________________
I am Addicted to Linux!
King is offline   Reply With Quote
Old May 23rd, 2006, 11:12 PM   #7
titaniumdecoy
Expert Programmer
 
titaniumdecoy's Avatar
 
Join Date: Nov 2005
Posts: 855
Rep Power: 3 titaniumdecoy is on a distinguished road
Send a message via AIM to titaniumdecoy
SmallBox smBox[][] = new SmallBox[xMax][yMax]; will create an array of null values of the specified dimensons. You have to initialize each index individually, eg, smBox[0][0] = new SmallBox();.
titaniumdecoy is offline   Reply With Quote
Old May 23rd, 2006, 11:49 PM   #8
titaniumdecoy
Expert Programmer
 
titaniumdecoy's Avatar
 
Join Date: Nov 2005
Posts: 855
Rep Power: 3 titaniumdecoy is on a distinguished road
Send a message via AIM to titaniumdecoy
As far how to access the smBox[][] array in the Tetris class from the Piece class, I would suggest passing the array as an argument to the Piece constructor.

Alternatively, you could make smBox[][] static.
titaniumdecoy is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 9:43 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC