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

2015/9/16

How to use getWorld in Actor class.

1
2
danpost danpost

2015/9/17

#
Doaky wrote...
Thank you very much! I have learned a lot from this. I still have one other problem though.
while ( !getWorld(getObjects(Actor.Flower).isEmpty()) )
This gets the error "cannot find symbol - variable Actor" Am I using the wrong keyword for this?
Try 'Flower.class' instead of 'Actor.Flower'. Also, you are missing a couple of characters after 'getWorld(' -- it should be 'getWorld().getObjects('...
Doaky Doaky

2015/9/17

#
Everything works now, but when I manually place the actor I get a terminal error. "java.lang.NullPointerException at MazeRunner.<init>(MazeRunner.java:21) at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27) at java.lang.reflect.Constructor.newInstance(Constructor.java:513) at greenfoot.core.Simulation.newInstance(Simulation.java:635) at greenfoot.localdebugger.LocalDebugger$QueuedInstantiation.run(LocalDebugger.java:155) at greenfoot.core.Simulation.runQueuedTasks(Simulation.java:468) at greenfoot.core.Simulation.maybePause(Simulation.java:282) at greenfoot.core.Simulation.runContent(Simulation.java:213) at greenfoot.core.Simulation.run(Simulation.java:206):
danpost danpost

2015/9/17

#
You probably did not remove the code I originally gave you from your code (as posted previously on page 1 of this discussion, lines 31 through 33 of the MazeRunner class). Actually, those lines need to be placed before your statements that use 'worldWidth' and 'worldHeight'.
Doaky Doaky

2015/9/17

#
I moved it earlier. Screenshot Is this correct?
danpost danpost

2015/9/17

#
Doaky wrote...
I moved it earlier. Screenshot Is this correct?
I doubt it. I believe that 'getWorld' will return 'null' there. Again, I am not familiar with sofia, but I believe that the 'super' Actor call must be called before it will return a World object. It may not even then, until the constructor has completed its execution.
Doaky Doaky

2015/9/18

#
Thank you so much for your help, I finally got everything to work!
You need to login to post a reply.
1
2