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

2012/1/16

whats boolean

1
2
tylers tylers

2012/1/16

#
whats boolean
Akuhano Akuhano

2012/1/16

#
Boolean is basically a true/false variable type. Boolean Information Link
tylers tylers

2012/1/16

#
how do you sett it out
danpost danpost

2012/1/16

#
Let us say you need to know (in the code) if the scenario has been started or not. You could create a world instance boolean variable named hasStarted and set it to false
public boolean hasStarted = false;
then in the world class act() method you might have
public void act()
{
    if (!hasStarted && Greenfoot.mouseClicked(null))
    {
        hasStarted = true;
        // code for some action(s)
    }
    if (!hasStarted) return;
    // other code within act()
}
This would basically wait for the user to click the mouse before moving on in the scenario (maybe the action code would be to remove the title screen or instructions).
tylers tylers

2012/1/16

#
it keeps saying illegal start of an expression?
danpost danpost

2012/1/16

#
RE-EDITED: You may have to post a few lines around where the compiler tells you the error is for further assistance.
tylers tylers

2012/1/16

#
this is the coding for my world could you help me find the bracket thing
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

/**
 * Write a description of class house here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class house extends World
{

    /**
     * Constructor for objects of class house.
     * 
     */
    public house()
    
    {    
        // Create a new world with 600x400 cells with a cell size of 1x1 pixels.
        super(400, 600, 1); 
        soilier gunman = new soilier ();
        addObject(gunman,200,550);
        zombie zombie = new zombie ();
        addObject(zombie,200,60);
        
    
        public boolean hasStarted = false;
    
            public void act()
{
    if (!hasStarted && Greenfoot.mouseClicked(null))
    {
        hasStarted = true;
        // code for some action(s)
    }
    if (!hasStarted) return;
    // other code within act()
}
        
    }
}
danpost danpost

2012/1/16

#
Add a close curly bracket at line 25 ( } ) and remove line 40. NOTE: java naming convention has class names to be started with uppercase characters. Line 23 may be confusing to the compiler as the variable name is exactly the same as the class name. At this point (since changing the class name would be un-advisable), you may want to change the variable name. Make the line either
zombie Zombie = new zombie();
or anything else other than 'zombie'.
tylers tylers

2012/1/16

#
class, interface, or enum expected it now saying
danpost danpost

2012/1/16

#
tylers wrote...
class, interface, or enum expected it now saying
on what line?
tylers tylers

2012/1/16

#
27
danpost danpost

2012/1/16

#
re-post what code you have now.
tylers tylers

2012/1/16

#
looks like it on line 26 now
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

/**
 * Write a description of class house here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class house extends World
{

    /**
     * Constructor for objects of class house.
     * 
     */
    public house()
    
    {    
        // Create a new world with 600x400 cells with a cell size of 1x1 pixels.
        super(400, 600, 1); 
        soilier gunman = new soilier ();
        addObject(gunman,200,550);
        zombie Zombie = new zombie ();
        addObject(Zombie,200,60);}}
        
         public boolean hasStarted = false;
    
            public void act()
{
    if (!hasStarted && Greenfoot.mouseClicked(null))
    {
        hasStarted = true;
        viod removeObject(instuction)
    }
    if (!hasStarted) return;
    // other code within act()
}
        
    }
}
        
    
      
danpost danpost

2012/1/16

#
OK, remove the second '}' on line 24 and also remove line 40. If you kept your brackets aligned with their matches, these would be alot easier to spot.
tylers tylers

2012/1/16

#
working thanks
There are more replies on the next page.
1
2