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

2012/4/5

My world disappeared right after I compiled!

MakerOfGames MakerOfGames

2012/4/5

#
There was no syntax errors and I tried to compile it again, it didn't work. I tried to create new world, that didn't work. Also, I restarted it, no luck :(. Help!
davmac davmac

2012/4/5

#
Probably, you have an infinite loop in your world constructor. If you need help finding it, post your world code here.
tylers tylers

2012/4/5

#
that happens to me sometimes. i managed to fix it by restarting greenfoot.
davmac davmac

2012/4/5

#
tylers:
Also, I restarted it, no luck
I think you didn't read the message...
MakerOfGames MakerOfGames

2012/4/5

#
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) /** * Write a description of class TowerDefenceWorld here. * * @author (your name) * @version (a version number or a date) */ public class TowerDefenseWorld extends World { int level=0; /** * Constructor for objects of class TowerDefenceWorld. * */ public TowerDefenseWorld() { // Create a new world with 600x400 cells with a cell size of 1x1 pixels. super(600, 600, 1, false); prepare(); } public void level() { if(level==0) { GreenfootImage background = getBackground(); setBackground("bluerock.jpg"); background.fill(); } } /** * Prepare the world for the start of the program. That is: create the initial * objects and add them to the world. */ int UL=0; int MUL=0; int SL=0; int TSL=0; private void prepare() { while(UL<18) { Tile1 tile1 = new Tile1(); addObject(tile1, 105, UL*30+90); UL=UL+1; } while(MUL<15) { Tile1 tile1 = new Tile1(); addObject(tile1, 225, MUL*30+90); Tile1 tile140 = new Tile1(); addObject(tile140, 315, MUL*30+90); MUL=MUL+1; } while(SL<4) { Tile1 tile119 = new Tile1(); addObject(tile119, SL*30+135, 90); Tile1 tile130 = new Tile1(); addObject(tile130, SL*30+375, 90); SL=SL+1; } while(TSL<3) { Tile1 tile139 = new Tile1(); addObject(tile139, SL*30+225, 510); TSL=TSL+1; } } }
nooby123 nooby123

2012/4/5

#
Try using for() instead of while().
davmac davmac

2012/4/6

#
Hmm, nothing wrong that I can see with that code. How about the code for the Tile1 class?
nccb nccb

2012/4/6

#
As Davin says, there may be a bug in the Tile1 constructor. But also: you do try to add one object just out side the world (though I think you should see an exception thrown if that was the problem). When UL reaches 17, you'll try and add an object with Y coordinate being UL*30+90, which is 17*30+90, which is 600. Since your world is 600 high, the Y coordinates stretch from 0 to 599, so 600 is actually just outside the world. You'll need to adjust your formula slightly. And finally: in your last while-loop you use SL to calculate the X position, I suspect you wanted TSL there instead. But that doesn't relate to this issue.
ttamasu ttamasu

2012/4/6

#
deleted comment earlier
tylers tylers

2012/4/7

#
ive got the exactly the same problem. help
davmac davmac

2012/4/7

#
tylers, exact same problem = exact same solution :p ... but please start a new discussion to post your code to avoid getting things mixed up in this one.
You need to login to post a reply.