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

2021/4/17

Actor not in the World

Genota Genota

2021/4/17

#
Hello everyone! I've got a problem/error message that pops up when I touch my elevator_platform. So what I have done is the following... I referred my "Elevator_Rope2_1" to "MyWorld", so that when my "Elevator_Plattform2" executes the method "move" it also executes the method "down" in my "Elevator_Rope2_1" class. The Problem is now, that everytime I touch my platform I get the error message "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." and it referrs to my elevator_rope. But that shows, that it works all fine, but it cant execute the method "down" / move the rope down. I hope its not to difficult to understand. Here is my "Elevator_Plattform2" code:
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

/**
 * Write a description of class Elevator_Plattform2 here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class Elevator_Plattform2 extends Ground
{
    private int speed = 3;
    private int count = 0;
    
    World myWorld = getWorld();
    /**
     * Act - do whatever the Elevator_Plattform2 wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
    public void act() 
    {
        move();
    }  
    public void move()
    {
         if(isTouching(Player.class))
        {
        World myWorld = getWorld();
         MyWorld myworld = (MyWorld)myWorld;
         Elevator_Rope2_1 elevator_rope2_1 = myworld.getElevator_Rope2_1();
         setLocation(getX(), getY()+speed);
        Actor player = getOneIntersectingObject(Player.class);
        if (player != null) player.setLocation(player.getX(), player.getY()+speed);
        
        elevator_rope2_1.down();
    }
    }
}
Here is my "Elevator_Rope2_1" code:
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

/**
 * Write a description of class Elevator_Rope2 here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class Elevator_Rope2_1 extends Actor
{
    private int speed = 3;
    private int count = 0;
    /**
     * Act - do whatever the Elevator_Rope2 wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
    public void act() 
    {
        update();
    }    
    public void down()
    {
        setLocation(getX(), getY()+speed);
    }
    public void update()
    {
        
    }
    public Elevator_Rope2_1()
    {
     update();   
    }
}
PS: The double t´s for platform in my class names are intentionally. And of course the elevator rope is in the world...
danpost danpost

2021/4/17

#
The problem probably resides in your MyWorld class. Show its codes, please.
Genota Genota

2021/4/17

#
Okay nevermind I figured it out by myself... And yes the problem was in the MyWorld class. Thank you anyways!
You need to login to post a reply.