hi, im trying to change world when i hit an obstacle
but when i compile this code green foot stops responding and just comes up with
in the greenfoot terminal window, and then even when i restart greenfoot the project wont respond and i have to go back to a previously saved part of the project, anyway i could get round this issue?,
This is the code for the world i am calling if its any help
public void CollisionToken()
{
Actor Token;
Token = getOneObjectAtOffset(0,0,Token.class);
if(Token != null)
{
Greenfoot.setWorld(question);
}
}Exception in thread "AWT-EventQueue-0" java.lang.OutOfMemoryError: Java heap space Exception in thread "TimerQueue" java.lang.OutOfMemoryError: Java heap space java.lang.OutOfMemoryError: Java heap space
public class Question extends World
{
Play play = new Play();
Menu menu = new Menu();
Actor question = new Actor() {};
int lastQuestion = -1;
int score = 0;
int random;
Actor[] answer;
int[] randomPosition = {-1, -1, -1, -1};
String[][] questions = //first one=question, second one=correct answer
{
{"which base is not found in RNA?", "thymine", "cytosine", "adenine"},
{"Which of the following bonds are broken \n during DNA replication?", "hydrogen bonds between bases", "phosphodiester bonds", "covalent bonds between bases"},
{"How many base pairs are there in one \n full turn of the DNA double helix?", "10", "16", "64"},
{"Analysis of a sample of DNA found that 20 of the bases were adenin.\n What percentage of the bases would be pyrimidines?", "50", "25", "60"},
{"Which technique was used\n to determine the double-helical \n structure of DNA?", "Dray crystallography", "electrophoresis", "chromatography"},
{"Analysis of a molecule of DNA found it to contain \n200 adenine bases, 20% of the total number of bases \nin the strand.How many phosphate groups \ndid it contain?",
"0%", "15%", "80%"},
};
public Question()
{
super(600, 400, 1);
addObject(question, 0, 0);
createNewQuestion();
}
private void createNewQuestion()
{
if (answer != null)//delete previous question
{
for (int i=0; i<3; i++) removeObject(answer[i]);
}
answer = new Answer[3]; //declaring answer
random = Greenfoot.getRandomNumber(questions.length);//get random question
question.setImage(new GreenfootImage(questions[random][0], 18, Color.BLACK, new Color(0,0,0,0))); //displaying random question
question.setLocation(300,80); //setting location
for (int i=0; i<3; i++)//loop for each answer
{
whileLoop: while (true)//infinite loop
{
int x = Greenfoot.getRandomNumber(3);
for (int j=0; j<i; j++)
{
if (randomPosition[j] == x) continue whileLoop; //stop overlapping of answers
}
randomPosition[i] = x; //setting position of answer to randomly generated number
break;
}
answer[i] = new Answer(i==0, questions[random][i+1]);
addObject(answer[i], 200+answer[i].getImage().getWidth()/2, 200+randomPosition[i]*60);
}
}
private class Answer extends Actor
{
boolean correct;
String answer;
public Answer(boolean correct, String answer)
{
this.answer = answer;
this.correct = correct;
updateImage();
}
private void updateImage()
{
setImage(new GreenfootImage(answer, 20, Color.BLACK, new Color(0, 0, 0, 0)));//setting variable c to a transparent color
}
public void act()
{
if (Greenfoot.mousePressed(this))
{
if(correct)
{
Greenfoot.setWorld(play);
}
else
{
Greenfoot.setWorld(menu);
}
}
}
}
}

