Weird game freeze, need help knowing wky [SOLVED]


(Ferran Ruiz Sala) #1

Every time i die i wanna make a pop-up screen appear that lets u know that u died, your score and your maximum score so far. It looks like this:

public class DieScreen extends Entity
	{
		
		public function DieScreen(height:Number) 
		{
			var heighttext:Text = new Text(height.toString(), 15, 53, { color: 0x000000 } );
			var maxheighttext:Text = new Text(PlayerData.maxheight.toString(), 15, 88, {color: 0x000000} );
			var back:Image = new Image(Assets.DIESCREEN);
			var display:Graphiclist = new Graphiclist(back, heighttext, maxheighttext);
			
			x = FP.camera.x + 25;
			y = FP.camera.y + 100;
			layer = -100;
			
			graphic = display;
			
			FP.log("diescreen placed");
		}
		
		override public function update():void 
		{
			super.update();
			
			if (Input.pressed(Key.RIGHT)) {
				FP.world = new GameWorld();
			}
			if (Input.pressed(Key.LEFT)) {
				FP.world = new MenuWorld();
			}
		}

For some reason, when the height has more than one character (>= 10) the images don’t appear, but the log “diescreen placed” does trigger. Also everything freezes in place (i guess the world stops updating). Any ideas? I’m so lost.


(Bora Kasap) #2

Ä° have no idea. Nothing looks wrong here. May be about something else? Could you post your code for creating diescreen?


(Ferran Ruiz Sala) #4

Yes, for sure. Thats the issue, nothing looks bad at all, and with numbers form 0 to 9 it works perfectly. makes no sense to me :confused:

World has this function:

public function die():void {
			FP.log("you died");
			if (PlayerData.maxheight < height) {
				PlayerData.maxheight = height;
			}
			add (new DieScreen(height));
			
		}

Player calls it like this:

	public function kill():void
	{
		FP.log("you lost");
		world.remove(this);
		(FP.world as GameWorld).die();
	}

I dont even know where a problem could be :sweat_smile:


(Mike Evmm) #5

When’s kill() called? Also, I’d recommend doing things in a different order, like so:

FP.log("you lost");
(world as GameWorld).die();
world.remove(this);

Since:

It’s almost never a good idea to use FP.world for anything but actually setting the world. Don’t reference it to do collisions, or to count entities, or to add or remove entities. The only time you should be using it is when you do FP.world = new MyWorld().

Could you maybe add a trace to height.toString() and PlayerData.maxheight.toString(), to make sure it’s being parsed correctly? It’s strange though, to work with some values but not with others…


(Ferran Ruiz Sala) #6

I put them both inside the FP.log and they are nice and correct int numbers.

I changed the order and FP.world to world, didnt fix it.

kill is called when the player collides with certain types of objects or when he falls off the screen.

I dont even know any workaround, it’s so simple it hurts :frowning: Thanks for the help.


(Mike Evmm) #7

Indeed. Welp, it can’t hurt to ask, what’s PlayerData?


(Ferran Ruiz Sala) #8

A class where I plan to store variables relative to the game in general, independent to in which world we are: Archievements unlocked, high scores, etc. For the time being there’s only one variable which is intended to store your max height (your record):

package
{

public class PlayerData 
{
	public static var maxheight:Number = 0;
	
	public function PlayerData() 
	{
		
	}
	
}

}


(Bora Kasap) #9

it looks you’re storing this “height” variable in the world class. so, could you show us where are you updating this variable from?

Actually you can solve your problem quickly with adding a breakpoint to where you put “FP.log(“diescreen placed”);” line. Then you can check for this height variable really works fine or not? We want to be sure about you’re updating the height variable correctly, then we should think about if there is an issue with image creating…


(Ferran Ruiz Sala) #10

Inside the world’s update function:

height = Math.round(Math.abs((FP.camera.y / 100))) * 1.2;

I changed FP.log(“diescreen placed”) to:

FP.log(“diescreen placed. Wrote”, height.toString(), “and”, PlayerData.maxheight.toString());

It writes both of them correctly.

What you mean by adding a breakpoint? I don’t think i know what that is, sorry :confused:


(Bora Kasap) #11

omg, after all this answers… i can’t understand the problem… there is one last thing i can suggest you…

try change variable name “height” to something else because of entity class have an height variable already… actually your variable is a parameter, that shouldn’t make a difference… hope you solve it soon… :frowning:


(Ferran Ruiz Sala) #12

I’ve been fiddling around with it a bit:

If i have only the back get drawn (graphic = back) and i comment the textes, it works. If i leave anyone of the two textes it doesn’t.

It looks like it may be something about the .toString() function. Does it have any problem? Should i make the variables are ints instead of numbers? (They’re whole numbers anyway, but i don’t know…)

Is there any other way to write a variable in text that it isn’t .toString()?


(Bora Kasap) #13

String(x) === x.toString();


(Ferran Ruiz Sala) #14

Ok i discovered something… It freezes not from drawing the screen, but from removing the player. For some reason the world soesn’t stand the fact that the player doesn’t exist anymore and it stops…

I’ll try to discover why.

[EDIT] Ok think i got it! There was an enemy that moved according to the player movement and spawned from height = 10. When the player gets removed and hes on the screen he becomes crazy because he cant find him. I think that’s it ill try to fix it.


(Jacob Albano) #15

Do you have a debugger enabled? You’d have a much easier time isolating the crash.


(Ferran Ruiz Sala) #16

I’m not sure what you mean so i guess i don’t have XD How do i install one?


(Jacob Albano) #17

What are you using to develop?


(Ferran Ruiz Sala) #18

FlashDevelop. Is it the best option? I just followed tutorials here and there and got it recommended so i went with it.


(Jacob Albano) #19

That’s what I would have recommended. Are you compiling in debug or release mode?


(Ferran Ruiz Sala) #20

I used to do it in debug, but i found that release made it more similar than what it plays like online, and i dont really notice any difference when compling in debug. Does it give more accurated info on errors when compiling in debug or something? I don’t know if i have a proper debugger installed.


(Jacob Albano) #21

If you don’t compile in debug mode, it’ll never report any errors. Unless you skipped something when setting up Flashdevelop, you have a debugger all ready to go…but you’re preventing it from doing its job.

When your game throws an exception and crashes, the debugger (if it’s running) will display a window showing the error, and take you to the exact spot in your code where it came from.