Create implicit coercion error


(billy2000) #1

So i understood that recycle/create are better in my situation then add/remove,so i started to replace remove with recycle and add with create.But i got this error: col: 26 Error: Implicit coercion of a value of type Bullet to an unrelated type Class. when i replaced add with recycle in this line:

FP.world.create(new Bullet(x + 30, y + 19, 7, 0));

Can you guys tell me what do i do wrong?


(Ultima2876) #2

To use FP.world.create you need to provide the class type that you want to create:

(FP.world.create(Bullet) as Bullet).setup(x + 30, y + 19, 7, 0);

Be careful with blanket-converting a whole project to recycle/create! Thar be dragons! Basically, you’ll need to use setup(args) functions or the added() function in all of your objects instead of constructors for most stuff, but make sure constructors are used for all memory allocations. I made a post about this recently here. Also you have to be sure that all of your objects variables are being reset in that added() or setup(args) function; if not you’ll get subtle and difficult to debug issues from objects not resetting their variables when spawned. This can cause all kinds of crazy and unpredictable behaviour ranging from exceptions to collision bugs, logic bugs, physics bugs… pretty much anything. So make damn sure you’ve got that solid!


(billy2000) #3

Wow thx! Didnt know that,thx for telling me :smiley: