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

2014/6/16

Access an Integer from another class in Greenfoot?

Mint_Greenie Mint_Greenie

2014/6/16

#
Hi! I have a class called 'Bird' which extends Actor in Greenfoot. Inside the code of the class 'Bird' there is a variable which is:
public int score = 0;
I need to access this score from another class called 'MenuScore' this is because I want to display this score on the menu. To do that I think the only way is to declare that same integer from the 'MenuScore' class. Is this possible? I've tried changing that Integer from private to public and then specifying a getter and setter. Is there any way I can do this, and please provide an example because it'll really help later into my game. Any help is appreciated! Thank You, Mint_Greenie
Mint_Greenie Mint_Greenie

2014/6/16

#
Anybody know how to do this?
davmac davmac

2014/6/16

#
Pretty sure this is covered in tutorial #6. Please go through the tutorials.
Mint_Greenie Mint_Greenie

2014/6/16

#
Okay, thanks @davmac!
Mint_Greenie Mint_Greenie

2014/6/16

#
Oh. LOL. That was simple!!!!
Mint_Greenie Mint_Greenie

2014/6/16

#
@davmac: One problem. This game is a flappy bird game. It doesn't have separate objects. It keeps refreshing the pipes.
davmac davmac

2014/6/16

#
Can you clarify what you mean, and explain why this is a problem? Can't you just have a Bird accessor in the world which the MenuScore uses to get the score (for example)? The pipes don't seem to be relevant to me.
Mint_Greenie Mint_Greenie

2014/6/16

#
Never mind, @davmac. In my game this isn't possible, since I will need to change all of my code for the whole game. The scoreboard is displayed in the pipes and the game doesn't save somewhere in the users C:/ drive so the scoreboard won't be the same. Thanks for your help anyways! Mint_Greenie
You need to login to post a reply.