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

2012/1/29

identifier expected

tylers tylers

2012/1/29

#
line 37-38 not sure
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

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

    /**
     * Act - do whatever the soilier wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
    public void act()   
     
    
    {
       
         //public void delay(int 100)
    
    //if (Greenfoot.isKeyDown("space"))
    //{
    //getWorld().addObject (new shoot (), getX(), getY()-48);
    
    if (Greenfoot.isKeyDown("right"))
    {
    move(4);
    } 
    if (Greenfoot.isKeyDown("left"))
    {
     move(-4);
    }
    
    }

       public void delay(int 100)
    {
    if (Greenfoot.isKeyDown("space"))
    {
       getWorld().addObject (new shoot (), getX(), getY()-48);
    }
       
programmar programmar

2012/1/30

#
on line 41 it looks like it should be } instead of {. Or maybe just get rid of it.
danpost danpost

2012/1/30

#
It appears that line 36 is the end of your act() method, and line 38 appears to be a new method called delay. But that is not in the form of a method declaration (because '100' should be a variable name if it was supposed to be one). I do not believe you intended to start a new method at that point. I would, first off, move line 36 to line 44, and then, if line 38 was an attempt to cause a delay, remove 'public void' and add a semi-colon at the end of that line. Line 40 should probably read 'if ("space".equals(Greenfoot.getKey()))' so that each time the key is pressed a shot is fired, instead of continuously firing when the key is pressed.
plcs plcs

2012/1/31

#
Tylers, consider pressing CTRL + SHIFT+ I (please note that it is an i not an L), when inside the editor - this will attempt to fix the indentation of your class, and if you notice lines totally off with what you expect (a method's innards should be one indent more, and the closing bracket same as the methods beginning). That way you can tell if your methods start/end in the right places.
You need to login to post a reply.