Nothing is "stored" in body. It's just a variable, and as such it's volatile. That is to say, it loses what it used to contain every time you give it another value. Forget for a moment that Body is a type. Think of it as an Integer.
If I say
And then I say
Body no longer contains 1. The 1 was overwritten when I set it to 2. Well it's the same way with types. Every time you create a new type, the old one is gone. BlitzMax now has a garbage collector, so I mean that quite literally. Unless you've put it somewhere, it's gone, deleted, kaput.
EG:
When the second star is created, the first one is gone from the variable Body. Since I haven't stored it anywhere else, it's subsquently deleted by BMax's garbage collector.
Now go back and look at your create function. Body is a local variable. As soon as that function is run once in it's entirety, Body goes out of scope. That is to say, it ceases to exist and the contents are gone. Next time you run the function, the variable will be created afresh, but it won't contain what it contained before. So if you didn't store that newly created star, it would be lost.
The only reason you have any stars to work with at all is because you add them to the list. That's the only place they exist. So when you want to use any stars, you have to get them back from the list. There are many ways of doing this, but the easiest and probably the most common is to use For Local Blah:Star=EachIn StarList
Now note again, it's YET ANOTHER local variable. It's only holding that one star at a time, and it only holds it temporarily. Once the function ends, it's gone again, and the only stars you have are.. you guessed it.. in your list.
Was that explanation any better?
If I say
Global Body:Int=1
And then I say
Body=2
Body no longer contains 1. The 1 was overwritten when I set it to 2. Well it's the same way with types. Every time you create a new type, the old one is gone. BlitzMax now has a garbage collector, so I mean that quite literally. Unless you've put it somewhere, it's gone, deleted, kaput.
EG:
Type Star Field X:Int,Y:Int End Type Global Body:Star=New Star Body.X=10 Body.Y=10 Body=New Star Body.X=20 Body.Y=20
When the second star is created, the first one is gone from the variable Body. Since I haven't stored it anywhere else, it's subsquently deleted by BMax's garbage collector.
Now go back and look at your create function. Body is a local variable. As soon as that function is run once in it's entirety, Body goes out of scope. That is to say, it ceases to exist and the contents are gone. Next time you run the function, the variable will be created afresh, but it won't contain what it contained before. So if you didn't store that newly created star, it would be lost.
The only reason you have any stars to work with at all is because you add them to the list. That's the only place they exist. So when you want to use any stars, you have to get them back from the list. There are many ways of doing this, but the easiest and probably the most common is to use For Local Blah:Star=EachIn StarList
Now note again, it's YET ANOTHER local variable. It's only holding that one star at a time, and it only holds it temporarily. Once the function ends, it's gone again, and the only stars you have are.. you guessed it.. in your list.
Was that explanation any better?