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

2018/6/6

incompatible types: java.lang.Class<lifeboard> cannot be converted into greenfoot.Actor

1
2
3
4
5
danpost danpost

2018/6/6

#
ogy2014 wrote...
java.lang.IllegalStateException: Actor not in world. An attempt was made to use the actor's location while it is not in the world. Either it has not yet been inserted, or it has been removed.
Add the following after line 28 in the UFO class code given earlier (insert at line 29):
return;
danpost danpost

2018/6/6

#
ogy2014 wrote...
if the ufo doesnt appear at the start of the game it doesnt appear again at all
Where is the act method in your Space class?
ogy2014 ogy2014

2018/6/6

#
no clue
danpost danpost

2018/6/6

#
ogy2014 wrote...
no clue
Add one.
ogy2014 ogy2014

2018/6/6

#
k what should i put in it, the random ufo code?
danpost danpost

2018/6/6

#
ogy2014 wrote...
k what should i put in it, the random ufo code?
Yes (it is not supposed to be in the constructor).
ogy2014 ogy2014

2018/6/6

#
the freezing bug is still there but getting one after another is sorted
danpost danpost

2018/6/6

#
Did you do what I suggested earlier?
danpost wrote...
Add the following after line 28 in the UFO class code given earlier (insert at line 29):
return;
ogy2014 ogy2014

2018/6/6

#
is this it?
        if(Greenfoot.getRandomNumber(1000) == 1)
        {
            addObject(new UFO(), 1, 70);
            return;
        }   
ogy2014 ogy2014

2018/6/6

#
oh wait sorry ill do it
ogy2014 ogy2014

2018/6/6

#
i am still getting the error message which says its not in the world or whatever
danpost danpost

2018/6/6

#
ogy2014 wrote...
i am still getting the error message which says its not in the world or whatever
Show (copy/paste) entire error output and post revised UFO class code.
ogy2014 ogy2014

2018/6/6

#
revised UFO code
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

/**
 * Write a description of class UFO here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class UFO extends Actor
{
    /**
     * Act - do whatever the UFO wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
    public void act() 
    {        
        if(getX() < 799)
        {
            move(4);
        }
        else
        {
            getWorld().removeObject(this);
        }
        
        Actor playermissile = getOneIntersectingObject(PlayerMissile.class);
        if (playermissile != null)
        { 
            Space space = (Space) getWorld();
            space.scoreboard.add(100);
            space.removeObject(playermissile);
            space.removeObject(this);
            return;
        }
    }    
}
error log java.lang.IllegalStateException: Actor not in world. An attempt was made to use the actor's location while it is not in the world. Either it has not yet been inserted, or it has been removed. at greenfoot.Actor.failIfNotInWorld(Actor.java:711) at greenfoot.Actor.getOneIntersectingObject(Actor.java:958) at UFO.act(UFO.java:26) at greenfoot.core.Simulation.actActor(Simulation.java:604) at greenfoot.core.Simulation.runOneLoop(Simulation.java:562) at greenfoot.core.Simulation.runContent(Simulation.java:221) at greenfoot.core.Simulation.run(Simulation.java:211)
ogy2014 ogy2014

2018/6/6

#
the at UFO.act(UFO.java:26) is the bugged line of code
danpost danpost

2018/6/6

#
ogy2014 wrote...
the at UFO.act(UFO.java:26) is the bugged line of code
That is not where I suggested you put the return statement.
There are more replies on the next page.
1
2
3
4
5