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

2016/12/12

Global Variable?

Corvus Corvus

2016/12/12

#
import greenfoot.*; 
 
public class Place01 extends World
{
    private int timer = 1200; 
    GifImage gif = new GifImage("Level1.gif");
    boolean colored = false;
    int size;
    public static final GreenfootSound Ranting = new GreenfootSound("Ranting.mp3");
    public static final GreenfootSound RainSounds = new GreenfootSound("RainSounds.mp3");
    Dots dots = new Dots();
    TextChar01 textchar01 = new TextChar01();
    TextChar02 textchar02 = new TextChar02();
    TextChar03 textchar03 = new TextChar03(); 
    public static boolean SequenceDone = false; 
How would I make this change and affect another actor? If (SequenceDone = True) on the other actor -
public class Char extends Actor

This doesn't seem to work.

Thanks!
{
public void act() 
{
if (SequenceDone = false)
    {
danpost danpost

2016/12/12

#
In line 9, you are assigning 'false' to the field and then using it as the argument for the 'if' condition. To compare 'false' to the current value of the field, you need to use the conditional equality symbol, which is two equal signs back-to-back:
if (SequenceDone == false)
Since the field is already a boolean value, you can more simply write this as:
if ( ! SequenceDone )
which is read "If not sequence done". Now, this still does not allow the field to be found from the Actor subclass. The class (static) field is in your Place01 class; therefore, you need to refer to it from another class as 'Place01.SequenceDown', making line 9:
if ( ! Place01.SequenceDown )
Corvus Corvus

2016/12/12

#
The world won't initialise right after I implemented this? There's no errors visible, strange.
danpost danpost

2016/12/12

#
Corvus wrote...
The world won't initialise right after I implemented this? There's no errors visible, strange.
I presume that none of the classes in the classes section of the ide have diagonal lines through them (meaning that there was a problem with compiling its code); and, therefore, it is the construction of your initial world that is the issue. Show the complete code for your initial world, to start.
Corvus Corvus

2016/12/12

#
There's diagonal grey lines on all of the World boxes and some of the actors.
danpost danpost

2016/12/12

#
Corvus wrote...
There's diagonal grey lines on all of the World boxes and some of the actors.
And what happens when you press Ctrl-K? do the diagonal lines remain?
You need to login to post a reply.