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

2016/12/18

How to declare an Varible which could be used by different Actors ?

WombatInCombat WombatInCombat

2016/12/18

#
I´m pretty new at Greenfoot and I`m trying to program a Little Game, but I´m in Need for an Varible which is >public<... My first try was sth. like this : public int xy; , but i guess that was totally wrong ^^. Would be nice if anyone could tell me how to do this ;)
Nosson1459 Nosson1459

2016/12/18

#
In your world you have to put:
public int variableName=1;
, then in your actor you can call it by doing:
WorldName world=(WorldName)getWorld();

// and

world.variableName=2;
.
danpost danpost

2016/12/19

#
What is the purpose of the "variable"? -- what does the value of it represent and how will it be used? Is it really a variable or is it actually a constant value? Where are you trying to put it and where are you trying to access its value from (give class names and indicate what class they extends -- World or Actor)?
You need to login to post a reply.