Classes must not be nested


(Gil) #1

I got this error out of nowhere in Main.as. Don’t have a clue as to how to get around it. Please help :d


(Gil) #2

The error actually occurs when I try to initialize another world, like a Main Menu, or a GameWorld. I can’t currently get anywhere from the Main Class because of this issue and it happened out of no where.


(azrafe7) #3

Can we see some relevant code?


(billy2000) #4

Ah ninjaed…wanted to say exact same words XD


(Ultima2876) #5

I’m guessing it’s a forgotten } somewhere or an extra {.


(Gil) #6
package 
{
	import net.flashpunk.Engine;
	import net.flashpunk.FP;
	import net.flashpunk.World;
	/**
	 * ...
	 * @author Gilberto Velez
	 */
	public class Main extends Engine
	{
		public function Main():void
		{
			super(640, 480,30,false);
			FP.console.enable();
		}
		
		override public function init():void 
		{
			super.init();
			trace("Engine started");
			FP.world = new GameWorld();
			
			
		}
	}
}

(Gil) #7

I cannot find anything wrong with my Main.as class whatsoever, other times though I get the same error inside the Engine.as. I have no idea what to do or how this problem came about.


(azrafe7) #8

Mmmhh… it seems ok to me. Can we take a look at the GameWorld class too?

Have you tried redownloading FlashPunk (maybe your Engine.as got corrupted someway)?


(Gil) #9

I figured maybe my engine class did get corrupt, so I re-downloaded flashpunk, twice. I re-set my main class to main document class twice over as well. I even deleted my main class and restored it, twice.

package  
{
	import net.flashpunk.FP;
	import net.flashpunk.World;
	import flash.geom.Point;
	import net.flashpunk.Entity;
	import ShihTzu;
	import Car;
	import vehicleFront
	import Ground;
	import Road;
	import Road2;
	import Road3;
	/**
	 * ...
	 * @author Gilberto Velez
	 */
	public class GameWorld extends World
	{
		public var time:Number = 1;
		public var Etime:Number = 1;
		public var Wtime:Number = 1;
		
		public var minTime:Number = .85; //Fastest spawn rate;
		public var maxTime:Number = 1.25;  //Slowest spawn rate;
		
		public var minTime2:Number = 3;
		public var maxTime2:Number = 4;
		
		public static var scrollSpeed:Number = 50;
		
		
		
		public function GameWorld()
		{
			
		}	
		
		override public function update():void 
		{
			super.update();
			
			//FP.world.camera.x += FP.elapsed * scrollSpeed;
			
			time += FP.elapsed;
			Wtime += FP.elapsed;
			Etime += FP.elapsed;
			
			if (Etime >= 1)
			{
				Spawn();//Spawn when Timer is positive;
				Etime -= FP.random * (maxTime * minTime) + minTime; //Timer -= randomly .5 or 1.5 seconds;
			}
			
			if (Wtime >= 5)
			{
				Spawn2();
				Wtime -= FP.random * (maxTime2 * minTime2) + minTime2;
			}
			
			if (time >= 20)
			{
				Car.CAspeed ++;
				scrollSpeed += 25;
				trace("faster");
				time -= 20;
			}
		}
		
		override public function begin():void 
		{
			super.begin();
			
			add(new ShihTzu);
			add(new Ground);
			add(new Ground2);
			add(new Ground3);
			add(new Road);
			add(new Road2);
			add(new Road3);
			spawnSideWalk();
		}
		
		public function Spawn():void
		{
			var c:Function = FP.choose(carSpawn, policeCarSpawn, taxiCarSpawn);
			c();
		}
		
		public function Spawn2():void
		{
			var c:Function = FP.choose(manHoleSpawn, blockadeSpawn);
			c();
		}
		
		public function carSpawn():void
		{
			var _car:Car = FP.world.create(Car) as Car;
			add(_car);
		}
		
		public function policeCarSpawn():void
		{
			var _police:policeCar = FP.world.create(policeCar) as policeCar;
			add(_police);
		}
		
		public function taxiCarSpawn():void
		{
			var _taxi:taxiCar = FP.world.create(taxiCar) as taxiCar;
			add(_taxi);
		}
		
		public function manHoleSpawn():void
		{
			var _manhole:ManHole = FP.world.create(ManHole) as ManHole;
			add(_manhole);
		}
		
		public function blockadeSpawn():void
		{
			var _blockade:Blockade = FP.world.create(Blockade) as Blockade;
			add(_blockade);
		}
		
		public function spawnSideWalk():void
		{
			var _sidewalk:SideWalk = FP.world.create(SideWalk) as SideWalk;
			var _side2walk:SideWalk2 = FP.world.create(SideWalk2) as SideWalk2;
			var _side3walk:SideWalk3 = FP.world.create(SideWalk3) as SideWalk3;
			
			add(_sidewalk);
			add(_side2walk);
			add(_side3walk);
		}
	}
}

(Gil) #10

I found the problem, I was relying on input from a static variable, from another class that I was testing, the code was unfinished though so I deleted it to show you what my GameWorld class would normally look like.

Out of curiosity, I tried compiling exactly what i’m showing you. It works.

That still leaves this question though if you could answer it.

I’m currently attempting to design a “Menu” screen where I select one from several entities, which will be the main player once I enter the actual game world.

It would be like “Select your character!”
Then, “Okay, press the space bar!”
Then, the GameWorld initializes with that character chosen to be the player. I run into errors like this one every time I attempt it. Its frustrating that I can’t go from Main.as > Menu.as > Gameworld.as. I can only go Main.as straight to GameWorld without errors.


(Jacob Albano) #11

See if removing :void makes a difference.


(Zachary Lewis) #12

Almost all of your work with FlashPunk will be done inside a world. Your path should look something like this:

Main -> CharacterSelectWorld -> GameWorld

You can use a static variable to save the selected character, or you can pass it to GameWorld as part of the constructor.


(Gil) #13

I made a Menu World and every time I try to do something simple on it like add a button entity I get this same error. Except I removed :void from the main constructor and now I get the error from the Engine class declaration.

Edit: AND!! Nevermind! I included parameters in that “button entity” that caused the problem! That error though was totally irrelevant to the actual error message though so the confusion lead me to believe that mysterious outside forces were f***ing with me.


(Ultima2876) #14

Yup, one problem with errors like that one is the compiler doesn’t fully understand what’s going on. If it sees this for example:

public override function blah(): void
{

} }

It sees that extra bracket at the end as closing whatever class is above it. It might not run into a situation where that technically becomes a problem until later in compilation - even possibly in another file. It makes those kinds of bugs hard to catch. That’s one reason why I always recommend proper usage of ; - code like this suddenly becomes a problem if you don’t make a habit of it:

var myVar: Number = 0
var entity: Entity = new Entity
(FP.world.create(TestButton2) as TestButton2)

It sees my FP.world.create call which would be perfectly valid if there were ; as an erroneous argument to the new Entity constructor.