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

2014/11/8

Can i call a variable int of a class from an other class? How?

largowinch123 largowinch123

2014/11/8

#
Hi, i'm new in Greenfoot, and I've got a problem. My crab can shoot and he has munition. In the class crab, i have the variable int munition = 50 defined. I've got an other class, which name is Objects. I want to say to objects that, when munition <=30, it appear an object (it is a chest). I don't know if that is possible (call a variable int from an other class), and how can i do it. PLEASE FASTER HELP. I NEED IT FOR MONDAY. PD: Sorry if someone don't understand something beacuse of my english. I am still learning English. Thank you.
danpost danpost

2014/11/8

#
You do not need another class (called Objects) to create a Chest actor. You can do that from the Crab class. After the line that decrements the munition field, use an 'if' statement to add a chest to the (same) world the crab is in if the value of munition has dropped to or below 30.
largowinch123 largowinch123

2014/11/8

#
Your right!! Thank you very much! It was easier that i think it.
You need to login to post a reply.