This site requires JavaScript, please enable it in your browser!
Greenfoot_back
Back to discussions
Avatar2_thumb
tallyaka wrote ...

2012/2/22

Making things happed when in a specific world

Avatar2 tallyaka

2012/2/22

I want to make it so that my actor switches worlds when he goes to the edge of the screen but I can't figure out how to make him go to a different world depending on what world he's in. I tried using the getWorld() command but I couldn't figure out how to make it work.
Smalldav_thumb davmac

2012/2/23

tallyaka, please post the code you tried and then we can help you to fix it.
Avatar2 tallyaka

2012/2/24

this is using an edditted code from mover which is as follows:
Design_r280o1660s1000f10000t0z30d2x0y0 danpost

2012/2/24

I have not done too much with working with different worlds, but I do know the use of '==' is not a good idea with worlds. Use the 'isInstanceOf(Object object)' method instead.
. I think I have them in the correct order.
Smalldav davmac

2012/2/24

Are Greece1 and Greece2 world classes, or world objects? Do you get a compiler error - if so, on which line, and what does it say? Danpost: I'm dubious of the code you posted. Perhaps you meant:
This assumes that Greece1 is a class, of course. You could just as well do:
Avatar2 tallyaka

2012/2/25

with this it says "cannot find symbol - class Greece2. It definitely exists and is a seperate world.
and for this it says the in cannot find the variable Greece1
402377_2911817076873_1304015802_3183781_998552265_n Duta

2012/2/25

This *should* work. I haven't tested it, just coded it into the reply box.
Smalldav davmac

2012/2/25

with this it says "cannot find symbol - class Greece2. It definitely exists and is a seperate world.

But is it a class, or a reference? The Greenfoot.setWorld() method requires a world instance as a parameter. Try replacing: Greenfoot.setWorld(Greece2); with: Greenfoot.setWorld(new Greece2()); (Although, the error message doesn't really make sense - are you sure that's what it says with the code you posted?)
Avatar2 tallyaka

2012/2/26

OK, I think it's all working now except the
part. That's my problem.
402377_2911817076873_1304015802_3183781_998552265_n_thumb Duta

2012/2/26

Did you notice my post...?
Smalldav davmac

2012/2/26

Or mine, from 2 days ago? if (Greece1.class.isInstance(getWorld()))
402377_2911817076873_1304015802_3183781_998552265_n Duta

2012/2/26

davmac wrote...

Or mine, from 2 days ago? if (Greece1.class.isInstance(getWorld()))

Fair enough - I'm just going to leave this thread alone now: he's got multiple answers, he just needs to see that they're there
Avatar2 tallyaka

2012/2/27

That's my code, and it compiles, but it doesn't work. If I go to the edge of the world I don't switch worlds :( Just FYI I also have the World code that Duta posted earlier
Avatar2_thumb tallyaka

2012/2/27

Nevermind! I got it to work! Thanks so much for all your help! I really appreciate it!
You need to login to post a reply