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

2017/1/27

Trouble with getWorldOfType()

valdes valdes

2017/1/27

#
From an Actor class, I use lines like this
getWorldOfType(FrogWorld.class).finJuego();
which works fine offline, but when I post the game on this web site, crashes. I already find a solution, using the line
((FrogWorld)getWorld()).finJuego();
My question/ comment is, is it a bug?
danpost danpost

2017/1/27

#
valdes wrote...
From an Actor class, I use lines like this
getWorldOfType(FrogWorld.class).finJuego();
The 'getWorldOfType' method is not part of greenfoot. You will need to show the code to that method.
valdes valdes

2017/1/27

#
danpost, yes it is part of Greenfoot. A method in the Actor class. Copy and paste from the API: getWorld public World getWorld() Return the world that this actor lives in. Returns: The world, or null if this actor is not in a world. getWorldOfType public <W> W getWorldOfType(java.lang.Class<W> worldClass) Return the world that this actor lives in, provided that it is an instance of the given "worldClass" class (i.e. that it is an instance of worldClass or one of its subclasses). Returns: The world this actor is in, or null if either this actor is not in a world Throws: java.lang.ClassCastException - If the actor is in a world, but not one that is an instance of worldClass or one of its subclasses
danpost danpost

2017/1/27

#
valdes wrote...
danpost, yes it is part of Greenfoot. A method in the Actor class. Copy and paste from the API: < Pasted Text Omitted >
Funny. The online documentation does not have that method included in it.
valdes valdes

2017/1/27

#
You are right. And that is the bug! One Actor class online, another one offline in the programming environment, and both say version 2.5. Hope some moderator check this out.
You need to login to post a reply.