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

2013/3/27

Referencing Objects

Gingervitis Gingervitis

2013/3/27

#
I am trying to reference two different counter classes from one class but it isn't compiling. I think I used the wrong code.....
Counter2 counter2 = new Counter2();
        addObject(counter2, 184, 61);
        Counter counter = new Counter();
        addObject(counter, 51, 23);
        
        Crab crab = new Crab(counter ,counter2);
        addObject(crab, 287, 286);
danpost danpost

2013/3/27

#
If you are getting an error message, please post the message and the code with the highlighted line indicating which line was highlighted. If not, explain the usages of the two counters and show the code for your Crab constructors.
Gingervitis Gingervitis

2013/3/27

#
the error message is :cannot find symbol - constructor Crab(Counter, Counter2) Here are the constructors from my class:
 public Crab(Counter pointCounter)
     {
          counter = pointCounter;

     }
     
     public Crab(Counter2 pointCounter2)
     {
          counter2 = pointCounter2;

     }
davmac davmac

2013/3/27

#
So, you don't have a constructor that takes both a Counter and a Counter2 argument, but you are trying to call one with this line: Crab crab = new Crab(counter ,counter2); Add a constructor which takes both, and it will work.
Gingervitis Gingervitis

2013/3/27

#
Right now it is two separate constructors right?
Gingervitis Gingervitis

2013/3/27

#
I figured it out! Thank you. I didn't know you have more than one thing in the constructor.
Gingervitis Gingervitis

2013/3/27

#
For some reason, when I reference the counter(s) in my World class code, my actor disappears when the game starts but it still counts when it eats something. How can this be fixed? I made it work fine before....
Gingervitis Gingervitis

2013/3/27

#
I figured it out. I had two constructors for the same thing and only one was being called for.
You need to login to post a reply.