Hello Greenfoot people,
I need some help displaying a variable in the world.
I know that I need to do it with an actor, and I know how to do that with static text,
But I don't know how to do it when it's a variable.
The variable is "Timer", which is in the World class ("Haven").
I created a class named "Tijd"
In that class I created a variable named "Timer2"
that variable ("Timer2") gets the value of the variable that is in the World
I used the folowing code to get the variable from "Timer" (in the world) and place it in "Timer2".
I also used a small loop to check if it kept getting the correct value, which it does.
My question is, how can I display a variable (that of course keep showing the correct value in"Timer2") ?
I plan to use the class "Tijd" just for that.
Any help is highly appreciated.
int smalltimer = 0;
/**
* Act - do whatever the Tijd wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act()
{
int timer2 = ((Haven)getWorld()).timer;
if (smalltimer < 50)
{
smalltimer++;
}
if (smalltimer == 50)
{
System.out.println(timer2);
smalltimer = 0;
}
}
