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

2013/6/10

Is in world?

1
2
Phytrix Phytrix

2013/6/10

#
I'm now receiving the original error :o 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:663) at greenfoot.Actor.getOneIntersectingObject(Actor.java:912) at Hero.enemyContact(Hero.java:72) at Hero.act(Hero.java:58) In reference to the code: Actor wolf = getOneIntersectingObject(Wolf.class);
Zamoht Zamoht

2013/6/10

#
Haha :) I see... This is because the checkNextLevel is called first. Try put it in the bottom of the act method.
public void act()     
    {    
        if (getWorld() != null)  
       {  
           controls();    
           isFalling();    
           actAtWorldEdge();    
    
          enemyContact();    
    
           lifeCounter();    
           touchingPlatformRight();    
           animationCounter++;    
           checkNextLevel();  
        }  
    }  
I have a fix if this doesn't work, but this would be the best way to work around it.
Zamoht Zamoht

2013/6/10

#
If it works you can try and remove the if statement because I think that the act method is only called for actors in a world.
public void act()       
    {        
           controls();      
           isFalling();      
           actAtWorldEdge();      
      
          enemyContact();      
      
           lifeCounter();      
           touchingPlatformRight();      
           animationCounter++;      
           checkNextLevel();     
    }  
But try the other thing first.
Phytrix Phytrix

2013/6/10

#
The first solution works. Thanks a lot for all your help. I really do appreciate it. :)
Zamoht Zamoht

2013/6/10

#
I'm sorry it took me so long.. I should have seen the problem a little earlier, but well glad I could help.
Phytrix Phytrix

2013/6/10

#
No problem. Exploring the issue should definitely help me improve my programming skills :) Thanks again! /topic
You need to login to post a reply.
1
2