Entity Access Help!


(Ethan Smythe) #1

To Everyone!

Sorry for the spam! just wanting to ask you guys a quick question I am trying to access my enemy entity in my enemy class from my player class. but when I try I get an error when i run it “Error: Implicit coercion of a value of type Class to an unrelated type net.flashpunk:Entity.” sorry for the spam still new to flashpunk

Regards Ethan


(VanderJamesHum) #2

How and where are you trying to access the entity? This excellent tutorial in the main pages describes different fetching methods really well and should help.

http://useflashpunk.net/intermediate/accessing-entities.html


(Ethan Smythe) #3

I am using the “FP.world.remove(Enemy);” function which is in my player class. and when I collide with the enemy entity it will execute the remove code but for some reason when i define (Enemy) it gives me an error! and doesn’t run!


(VanderJamesHum) #4

I think the remove function in your player class is trying to remove the Class type Enemy, instead of an instance of that Enemy Class. I’d try putting the remove function in the enemy class update, after a collision check with a weapon or bullet or what have you

` if (collide(“weapon”, x, y )) { FP.world.remove(this); }`

So each Enemy is checking for collision, and if it collides it removes it self with .remove(this);


(Ethan Smythe) #5

when i type in enemy into FP.World.remove(Enemy) it puts the enemy class into it not the enemy entity so i think that maybe why i am getting an error because you can remove the class… still no enemy entity apearing


(Jacob Albano) #6

The problem is likely that you never actually define a variable called enemy, so when you type it your editor autocompletes it to Enemy, which is the class name.

Can you show us the block of code where you try do the removal? Without it we can only guess what your problem is.