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

2022/4/29

Changing variable value

ADAM68801 ADAM68801

2022/4/29

#
Hi I have variable in my world, and I want to change it in Actor code not in world. How can I do that????
Super_Hippo Super_Hippo

2022/4/29

#
private int something = 0;
public int getSomething() {return something;}
public void setSomething(int newValue) {something = newValue;}
public void addSomething(int newValue) {something += newValue;}
If the actor is in the world, you can then do this to set it to 100 for example.
((WorldClassName) getWorld()).setSomething(100);
You need to login to post a reply.