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

2016/11/1

How do I make a global variable, or at least something that works like one?

wasd wasd

2016/11/1

#
In the game I'm making I want to have some integers accessible to every actor. What ways are there to do this?
Super_Hippo Super_Hippo

2016/11/1

#
You could use a variable like this:
1
public static int varName = 123;
Then you can access it with ClassName.varName.
danpost danpost

2016/11/1

#
Use instance 'private int' fields in your world class and add a 'public int getInteger_()' for each one so the actors can access the value of them with (using MyWorld as world class name):
1
int value_ = ((MyWorld)getWorld()).getInteger_();
You can change the underscores simulateously to whatever, for example 'A', 'B', 'C', ..., for each field. Actually, you can name they whatever you want, I just wanted to point out that all underscored names are referring to the same field.
You need to login to post a reply.