Brain Stumper

Blitz3D Forums/Blitz3D Programming/Brain Stumper

Buggy(Posted 2007) [#1]
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?


big10p(Posted 2007) [#2]
You need to define your array as ships.ship[4], in your squadron type.


Buggy(Posted 2007) [#3]
I did.

Edit: (And it still doesn't work)


Yahfree(Posted 2007) [#4]
can you show us more code? (the type declaration ect)


Gillissie(Posted 2007) [#5]
What exactly doesn't work? Need more details.


Buggy(Posted 2007) [#6]
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?


big10p(Posted 2007) [#7]
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.


Buggy(Posted 2007) [#8]
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.