i'm writing a method that sets all objects of that class to the world.. problem is that i have 4 pretty mutch same classes "levels" that i want to add to the world randomly.. so i'm using a class controler to determine what class will be added.. sth like this..
and my set() method look's like this..
So im getting this error telling me that getWorld() method can't be referenced from a static context. But if I make my set() method just void, I cant reference it from main - controler method. How can i solve this confusion? can anyone help? :)
**This is a test code, just to make my levels appear randomly, this is my only problem left, so I'll be extra happy if smvn helps :)
void controler(){
if (izbor.length() == 0) { izbor = "0123"; }
// variable "izbor" is declared as a String, earlyer..
else {
int a = Greenfoot.getRandomNumber(izbor.length());
String b = ""+izbor.charAt(a);
int c = Integer.parseInt(b);
switch (c) {
case 0 : izbor = izbor.replaceAll("0","");
mapa1.set();
break;
case 1 : izbor = izbor.replaceAll("1","");
mapa2.set();
break;
case 2 : izbor = izbor.replaceAll("2","");
mapa3.set();
break;
case 3 : izbor = izbor.replaceAll("3","");
mapa4.set();
break;
} } }static void set(){
getWorld().removeObjects(getWorld().getObjects(Actor.class));
put1 p1 = new put1();
getWorld().addObject(p1, 250, 250);
}


