I need my main character to know what world he is in, so he receives a String from the world. I was hoping that this String (which its value is the same as the world's name) would be able to act as the class name needed to run a method from that world, but it compiles an error saying "cannot find symbol - class currentWorld". Here is the code (loosely) that I have written.
String currentWorld; //Tells what world Guy is currently in
public Guy (String checkWorld) //String received from the world in specific, specifying the world's name
currentWorld = checkWorld;
if(Greenfoot.isKeyDown("enter") & atDoor == true)
{
levelEnd = true;
((currentWorld)getWorld()).changeWorld(levelEnd);
}
Any idea why this wont work?
If I replace: ((currentWorld)getWorld()).changeWorld(levelEnd);
with: ((worldOne)getWorld()).changeWorld(levelEnd);
it works fine, but currentWorld's value is equal to "worldOne", so why won't it work?

