GLBasic forum

Main forum => GLBasic - en => Topic started by: mikiex on 2006-Apr-04

Title: types
Post by: mikiex on 2006-Apr-04
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?
Title: types
Post by: Kitty Hello on 2006-Apr-05
Yes.
Code (glbasic) Select
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.
Title: types
Post by: mikiex on 2006-Apr-05
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 :)
Title: types
Post by: Kitty Hello on 2006-Apr-05
If you make an array of a type:
Code (glbasic) Select
TYPE FOO
  bar
ENDTYPE

LOCAL foo[] AS FOO
DIM foo[10]
You can easily use the BOUNDS command:
Code (glbasic) Select
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:
Code (glbasic) Select
TYPE FOO
   bar[15]
ENDTYPE
Title: types
Post by: mikiex on 2006-Apr-05
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
Title: types
Post by: Kitty Hello on 2006-Apr-05
er... not really. BOUNDS simply gives you the number of items of an array.
Code (glbasic) Select
DIM a[5][7]

PRINT BOUNDS(a[ ], 0), 0,  0 // 5
PRINT BOUNDS(a[ ], 1), 0, 10 // 7
Title: types
Post by: mikiex on 2006-Apr-05
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?
Title: types
Post by: bigsofty on 2006-Apr-06
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.
Title: types
Post by: Kitty Hello on 2006-Apr-06
You can simulate adding to a dynamical list the Blitz way with REDIM. Thank you for your feedback, bigsofty.
Title: types
Post by: mikiex on 2006-Apr-06
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