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

2013/2/16

Error: Void type not allowed here PLEASE HELP ME

Eli.A Eli.A

2013/2/16

#
I'm trying to make it so that in my game an actor (EATER) creates a balloon (I spelled it wrong in the code but that is what I'm talking about) every 5 seconds. The problem is that I'm getting a Greenfoot error that says, "Void type not allowed here." I put the code for my EATER bellow. Please help me and ask if you need any more code.
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

/**
 * Write a description of class EATER here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class EATER extends Actor
{
    /**
     * Act - do whatever the EATER wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
    public void act() 
    {
        long lastAdded = System.currentTimeMillis();   
  
    long curTime  = System.currentTimeMillis();  
    if (curTime >= lastAdded + 5000) //5000ms = 5s  
    {  
        Ballon ballon = new Ballon
        (getWorld(). addObject(ballon,200,200));  
        lastAdded  = curTime;  
    }  
}  
}    
tylers tylers

2013/2/16

#
Should be:
        Ballon ballon = new Ballon();  
        getWorld(). addObject(ballon,200,200);  
        lastAdded  = curTime;    
Eli.A Eli.A

2013/2/16

#
tylers wrote...
Should be:
        Ballon ballon = new Ballon();  
        getWorld(). addObject(ballon,200,200);  
        lastAdded  = curTime;    
Okay, I'm not getting any syntax errors now, but the EATER is not creating balloons when I run the game.
danpost danpost

2013/2/16

#
Move line 17 to 13.
Eli.A Eli.A

2013/2/16

#
@Danpost Thank you so much!!!!!! But, I do have one more question. Instead of having all the balloons come from EATER, I want to make it so that they start at a random y position. I don't want them always start at EATER'S y-position.
danpost danpost

2013/2/17

#
Then change line 23 to
getWorld().addObject(ballon, 200, Greenfoot.getRandomNumber(getWorld().getHeight)-100);
I added the '-100' so they would not spawn near the bottom of the screen.
Eli.A Eli.A

2013/2/17

#
@Danpost I did what you said but now Greenfoot is saying, "Can not find symbol- variable get height (it's selecting the part in the new line that says get height). Here's the code.
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

/**
 * Write a description of class EATER here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class EATER extends Actor
{
    /**
     * Act - do whatever the EATER wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
    long lastAdded = System.currentTimeMillis(); 
    public void act() 
    {
    long curTime  = System.currentTimeMillis();  
    if (curTime >= lastAdded + 1000) 
    {  
        Ballon ballon = new Ballon();
        getWorld().addObject(ballon, 200, Greenfoot.getRandomNumber(getWorld().getHeight)-100);  
        lastAdded  = curTime;
    }  
}  
}    
danpost danpost

2013/2/17

#
Yeah, I forgot to put the parenthesis after it -- getHeight().
You need to login to post a reply.