Collision that would reset the world?


(Jacob Albano) #4

I’ve never had that white screen problem. If it was a problem with your code, you’d either get a compile error or a runtime exception.

Do me a favor, just to test something: try running this code:

var e:Entity = null;
e.x = 0;

If it causes a white screen, something is wrong with your error handling. It should pop up with a window showing the error.

You are running in debug mode, right?


(I'll tell you what I want, what I really really want) #5

I am. And It did freeze the game to death the second it was supposed to update.


(I'll tell you what I want, what I really really want) #6

That really kills me. I guess there’s not going to be any collision in my game.

Even if I try it on the entity, the Alice, it doesn’t work.


(Jacob Albano) #7

This is really bizzare. For the record, there’s nothing wrong with your code; it’s just that whenever an error is thrown your debug player doesn’t know how to handle it.

Try one more thing for me: instead of the code above, try throwing the error manually to make sure it’s the error handling that causes the white screen.

throw new Error("whatever");

It might help to uninstall Flashdevelop completely and reinstall it from scratch. Something must have gone wrong during the setup process.


(I'll tell you what I want, what I really really want) #8

again. white screen. I’m going to reinstall it now.


(I'll tell you what I want, what I really really want) #9

it works! I mean, I’m not getting the white screen!

but I’m getting this for:

	var b:BadOne = _alice.collide("badOne", x, y) as BadOne;

	if (b)
	{
		FP.world = new Alice_game_one();
	}

Error: Access of undefined property y. and the same for x

What I want to do is every time my character collides with an entity, any entity, It takes him to the beginning. Is there an easier way to do that without a headache?


(Jacob Albano) #10

Hmm…are you sure this is the code that causes the crash? The exception message should have line numbers that will show you where in the source the crash occurred. Not that I don’t believe you, I just can’t see anything here that would cause that particular error.

There’s no clean way (that I’m aware of) to check if any entity whatsoever is colliding with something. You could do this, but it’s kind of ugly and will probably be slow with a lot of entities in the world:

var all:Array = [];
world.getAll(all);

for each (var e:Entity in all)
{
    if (e.collideWith(this, x, y))
        //  restart the world
}

(I'll tell you what I want, what I really really want) #11

Fault] exception, information=TypeError: Error #1009: Cannot access a property or method of a null object reference.

that is, to line:

			if (e.collideWith(_alice, x, y))

(Jacob Albano) #12

Looks like e is null for some reason. I can’t think why that would be though…do you cast it or anything first?


(I'll tell you what I want, what I really really want) #13

Yes, I do as a matter of fact :D, but when I change it to let’s say “a”, it doesn’t change a thing. Except, now it’s throwing a white screen at me again.


(Jacob Albano) #14

Ugh >< I don’t know what to tell you about the white screen, sorry.

Changing the name of the e variable won’t have any affect whatsoever. If a cast fails, the result will be null. Just check the variable before using it, but after casting.

var all:Array = [];
world.getAll(all);

for each (var e:Entity in all)
{
    var enemy:Enemy = e as Enemy;
    if (!enemy) // invalid cast!
        continue;

    if (enemy.collideWith(this, x, y))
        //  restart the world
}

(I'll tell you what I want, what I really really want) #15

still white screen. I don’t know man. Something is terribly wrong here.


(Ultima2876) #16

Try reinstalling Java and make sure you’re installing the 32-bit version (even if you have a 64 bit OS). http://www.oracle.com/technetwork/java/javase/downloads/java-se-jre-7-download-432155.html - you want “Windows x86 Offline” (unless you’re on Linux).

For your original code, try this:

var b:BadOne = _alice.collide("badOne", _alice.x, _alice.y) as BadOne;

Also make sure you are testing with a debug flash player. Non-debug flash players will ignore exceptions and remove the offending object from the stage (in this case, FlashPunk) silently, giving you the white screen of death and zero useful information about what’s going wrong. Try this one: http://download.macromedia.com/pub/flashplayer/updaters/13/flashplayer_13_sa_debug.exe (download it to your flashdevelop directory and go into Tools > Program Settings > FlashViewer > External Player Path to point FlashDevelop to it).

If all that fails, wrap the offending code like this:

try
{
  //my code here
}
catch(e: Error = null)
{
  //write the error to the stage as a text field
  var tf: flash.text.TextField = new flash.text.TextField;
  tf.multiline = true;
  tf.Text = e.errorID + " - " + e.name + "; " + e.message + " [" + e.getStackTrace() + "]";
  FP.stage.addChild(tf);
}

This is not as good as proper error reporting through your IDE as it lacks features such as double clicking a line in the stack trace to go to that line in your code, but it’ll do in a pinch (I’ve done a LOT of this kind of debugging on embedded systems where I can’t run a proper debugger).


(Jacob Albano) #17

Wouldn’t it be wonderful if Flash had global error handling?

Come to think of it, that wouldn’t be too hard to add to Flashpunk, since everything runs inside one top-level engine function.


(Ultima2876) #18

Indeed. That’s probably actually only a 5 minute job.


Discussion: Global error handling
(I'll tell you what I want, what I really really want) #19

So, white screen is gone, thank you boys, but when the

var b:BadOne = _alice.collide(“badOne”, _alice.x, _alice.y) as BadOne;

if (b) // or if (b == true); { FP.world = new Alice_game_One; }

Is not working.

EDIT: Even tho I won’t quit, it’s frustrating that from all the problems I had with this game, collision is the one that will prevent me from submitting on Ludum Dare. Horrible.


(Jacob Albano) #20

Just to get it out of the way, your BadOne class does have its type set to “badOne”, right?

Are you accidentally using a semicolon after the if() again?

if (b);
{
    FP.world = new Alice_game_One;
}

That would definitely trip you up.


(I'll tell you what I want, what I really really want) #21

it does, it’s “badONE” actually.

I am not. And surprise, If I do, my old friend white comes along to play.

the fact that I have a backdrop doesn’t affect anything, does it?


(Jacob Albano) #22

Alright, that might just be the problem. Collision types have to be consistent in order to work; “badOne” and “badONE” are completely different as far as the world is concerned.

Other things to check are that each class has a hitbox or other collision mask, and that none of them have set collidable to false.


(I'll tell you what I want, what I really really want) #23

They both haven’t got collidable set, no other collision mask, they do have hitboxes and types.