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

2012/1/5

Problems with variables in my Breakout game.

Are1222 Are1222

2012/1/5

#
Hey guys so I'm having a fair bit of trouble trying to get a variable in my brick class (under actor) into my board class (under world). I've seen tuts on how to do it vice versa but never this way and I was wondering if there is a way. Any help would be greatly appreciated!
DonaldDuck DonaldDuck

2012/1/5

#
To change a variable in the world:
((WORLD_NAME) getWorld()).VARIABLE = true/false/int/etc.;
To assign a variable in the world to a variable in the actor
((WORLD_NAME) getWorld()).VARIABLE = THIS_ACTORS_VARIABLE;
Simply reference the world before you call getWorld() and it will get the specific world.
Are1222 Are1222

2012/1/5

#
Much appreciated will try it out in the morning :)
Are1222 Are1222

2012/1/5

#
Alright so I tried this and I got the message say "cannot find getWorld(). On closer inspection of world API I found there was no getWorld method and in fact it is in the actor API. SO what shall I do? Also when I try Actor.getWorld() it says: non-static method cannot be referenced from a static context.
danpost danpost

2012/1/5

#
That is correct. That is, in the world class, there is no getWorld() method, because it would be the 'this'. Basically, it would be a reference to itself.
DonaldDuck DonaldDuck

2012/1/5

#
The code I gave you was intended for the actor class. Simply make a variable in the world class and use either of the codes I provided you with to modify that variable or check it.
You need to login to post a reply.