Hi,
I have not really looked at types yet, but how do they compare to blitz's versions of types,
examples in the help shows use for database type use "books" etc, I know this can be anything.
But how about an example if it is possible to use types in this way for say "aliens" or bullets, or a particle system?
Yes.
TYPE VEC2D
x
y
ENDTYPE
TYPE ALIEN
pos AS VEC2D
type
shield
firepower
ENDTYPE
TYPE BULLET
pos AS VEC2D
power
age
ENDTYPE
However using types might cause some compiler trouble still. Also, the Editor will not give you much aid (word completition), yet. Here's the most work to be done for future releases.
Thanks, but then how do you go through every instance of a type
I know you should use a for loop, but how do you know how many there
are of that type etc. - maybe I am being dumb :)
If you make an array of a type:
TYPE FOO
bar
ENDTYPE
LOCAL foo[] AS FOO
DIM foo[10]
You can easily use the BOUNDS command:
FOR i=0 TO BOUNDS(foo[], 0)-1
PRINT foo[i].bar, 0, i*10
NEXT
This also works with pre-dimed data inside the types:
TYPE FOO
bar[15]
ENDTYPE
Ok, does bounds mean the same as 'ALL' in blitz?
http://www.blitzbasic.com/Community/posts.php?topic=34757
A working example of keeping track of some aliens moving around
would be interesting
er... not really. BOUNDS simply gives you the number of items of an array.
DIM a[5][7]
PRINT BOUNDS(a[ ], 0), 0, 0 // 5
PRINT BOUNDS(a[ ], 1), 0, 10 // 7
My understanding of types in blitz is you can create many instances of a type
effectivley having an 1d array of them. People treat them as an alternative
to arrays for storing info
So you create 20 aliens of one "Type", then to process them all you do something like..
for type all do something
I have to say I have never actually used types in blitz myself :) so I am kind of grabing a straws,
sorry, it just looks to me as the functionality is slightly different.
Btw I do like the syntax of glbasic, but would "Class" be a better name?
To avoid confusion with "type" used in terms of data types ?
Like vec2D you mention in your example is a type (a data type)?
Did you choose Type as a name so people fimilar with blitz would understand?
Types in Blitz are more akin to dynamically allocated objects, with one 'type var' linking to the next via a linked list. Gernots, allhthough using dynamic arrays, are based on static data structures.
I prefer Gernots.
You can simulate adding to a dynamical list the Blitz way with REDIM. Thank you for your feedback, bigsofty.
Well if it is possible to use these types for say a simple particle system or aliens moving around on the screen it would be interesting to see an example of it in action