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

2011/11/20

Public Variables, we meet again

1
2
darkmist255 darkmist255

2011/11/23

#
Well changing the variable type to SpaceWorld did it :D (thanks, I think that will help lots with my troubles with references!). However it doesn't like:
    private void prepare()
    {
        castle = new Castle();
        addObject(castle, 300, 399);
    }
it doesn't like castle and says "cannot find symbol - variable castle". Aren't we defining the variable right now though? Or is it because there is no variable type given? Or am I just rambling?
darkmist255 darkmist255

2011/11/23

#
I changed the code to
    Castle castle = new Castle();
    private void prepare()
    {
        addObject(castle, 300, 399);
    }
Which should make it accessible, and I'm no longer getting said error. Let's hope :D.
darkmist255 darkmist255

2011/11/23

#
Oooh :D! No syntax errors anywhere, I've reorganized my code and redid all of my references. BUT when I compile, nothing shows up and I can't run/act. It compiles without error, just won't run. Probably just something dumb I did :D. Ever seen this happen before?
darkmist255 darkmist255

2011/11/23

#
Huzzah! Fixed it! It was as simple as this: It said it didn't like me accessing the non-static variable, so I changed this
Ball ball = new Ball();
to this
static Ball ball = new Ball();
and what do you know, it worked :D.
You need to login to post a reply.
1
2