Can't change current world through entity update [SOLVED]


(Sandro Sixarulidze) #1

So everything is self explanatory, I want to change world when space is pressed, and one of enteties is checking for that. But i recieve this error:

‘Cannot access a property or method of a null object reference.’

here is my code

package { import net.flashpunk.Entity; import net.flashpunk.graphics.Text; import net.flashpunk.utils.Input; import net.flashpunk.utils.Key; import net.flashpunk.FP;

/**
 * ...
 * @author bootcher007
 */
public class starttext extends Entity 
{
	var txt:Text;
	var cnt:int;
	public function starttext() 
	{
		cnt = 0;
		txt = new Text("Pres Spacebar to start!");
		graphic = txt;
		txt.scale = 3;
		
	}
	public override function update():void 
	{
		if (cnt <= 20)
		{
			txt.text = "";
			cnt++;
		}
		else if(cnt > 20)
		{
			cnt++;
			txt.text = "Pres Spacebar to start!";
		}
		if(cnt > 40)
		{
			cnt=0;
		}
		if (Input.check(Key.SPACE))
		{
			FP.world = new Level;
		}
	}
}

}


(Sandro Sixarulidze) #2

Never mind, i found the problem, it wasn’t in changing, it was in level world class itself, i first added the entity and then defined it (so when i added it, it was null) noob mistake i know.


(Martí Angelats i Ribera) #3

Hey, add a [solved] At the start of the title so it’s easier to see that this was solved :wink: