Brain Stumper

Blitz3D Forums/Blitz3D Programming/Brain Stumper

Though this isn't really hard, and I think I've done things like this before, I've thought hard for at least two minutes, and I still can't figure out how to do it.

So, basically, I have ships. Some ships belong to squadrons of five ships each. I've decided to store squadrons as types with the variable ships[5] to hold all of the ships in the squadron.

My problem comes when adding ships to a squadron. Say I create a new squadron:
sq.squadron = New squadron


And now I try to add a ship to it:
s.ship = New ship
sq\ships[0] = s


Which doesn't work. Any ideas?

You need to define your array as ships.ship[4], in your squadron type.

I did.

Edit: (And it still doesn't work)

can you show us more code? (the type declaration ect)

What exactly doesn't work? Need more details.

Whoops. Never mind. It does work. Typo.

But now I have a new question. If I first create a ship, and then add it to an array of ships, does this create some sort of memory leak? Is the ship now existent in two places, and I have to delete the single ship, or is it okay?

No, you're just placing the pointer to the same ship instance in the array.

A new type instance is only ever created when you use the New command.

Good, thanks. Probably the one thing that keeps me using Blitz is my utter lack of understanding of pointers. I knew that this was a pointer thing, but didn't know if it just used the pointer or copied the whole entity.

Thanks a lot.