#Skipping references when convenient

16 messages · Page 1 of 1 (latest)

silver vault
#

I have no idea if I'm even going about this the right way, but I fear for refactoring my entire project.

I'm making a bullet hell game, and each boss battle is run through phases in the enemy class. The phase scripts reference the enemy node, and both handle & reference bullet spawning. If I want a bullet to turn mid-trajectory, I have to create a bullet as a variable, then give it its own function below. something like:

func attack():
  while(can_enemy_attack):
    var bullet: = spawn_bullet(args)
    move_pattern(bullet)
  await(timer1)

func move_pattern(bullet):
  await (timer2)
  bullet.angle += 90

There are walls surrounding the battles which the bullets can collide and dissipate on, player bombs which can erase bullets, and bullets will naturally despawn after existing long enough.
My question is, how should I handle and reference a bullet so that the game can ignore a deleted reference without having to type "if bullet != null" in front of every reference? is there an elegant solution to this?

#

please ping with responses/solutions

silver vault
#

bumping this, any advice is appreciated

steady kestrel
#

Ideally, bullet behaviour after firing should be handled by the bullet itself, which would avoid any issues like that.

#

You could of course have different types of bullets, like a BendBullet that has time_until_bend and maybe bend_angle, and after firing it'll wait time_until_bend, then add bend_angle to its moving angle

#

This would also reduce how bloated your enemy script gets

#

Since the enemy script would no longer be referencing bullets after firing them, you'd never run into null references

#

The bullets, of course, won't refer to themselves after they've been destroyed

silver vault
#

that would necessitate making a bunch of different, unique bullet resources for every pattern, wouldn't it?

#

it might be difficult if the bullet needs to react to external calls anyway as well (like, for example, a gravity well that affect bullets' trajectories)

steady kestrel
steady kestrel
potent wharf
#

but (and I can't vouch that this is a good idea, for clarity, though it seems to work)

#

I just have everything in groups and scripts that do things to all nodes in said groups

silver vault
#

that might be an idea... interesting