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

2013/5/6

World to another world problem

holla holla

2013/5/6

#
Hey greenfoot fans, i want to send a list of booleans from world1 to world2. these booleans are like settings for the rest of the game. I tried it with methods, but non-static problems. Has anyone an idea?
Gevater_Tod4711 Gevater_Tod4711

2013/5/6

#
First you need to create some getter and setter methods in your world classes to submit the values you need. Then when you try to set the world you do this:
World2 myWorld = new Worlds2();
int value = ((World1) getWorld()).getValue();
myWorld.setValue(value);
Greenfoot.setWorld(myWorld);
If this code is executed in the world class you don't need the getWorld() and the cast to World1. Instead of World1 you use the name of the current world and instead of World2 the name of the new world. And you have to change the methods to the methods you declared. However they are called.
danpost danpost

2013/5/6

#
You are probably trying to run those methods on the Class object and not on an instance of that class. First create the new World2 object, then run the methods on that world and set that world as the current world.
World2 w2 = new World2();
w2.setValues(boolOne, boolTwo, boolThree);
Greenfoot.setWorld(w2);
holla holla

2013/5/6

#
Thanks, my problem was excactly that. Now it's solved :)
You need to login to post a reply.