| This article is a stub. You can help improve Game Design Novice by expanding it. |
A Type (also known as Struc, user defined type, UDT) can store multiple pieces of data of different data types.
Types vs. Strucs
In some game programming languages, types are known as types. In others, they are known as Strucs. There is generally no difference between the two except their name. In general, if a game programming language uses BASIC syntax, the name "type" is used. If it uses C-syntax, it is known as a "struc." One exception to this rule is Basic4GL which uses BASIC syntax but also calls types "strucs".
Uses of Types
Types make it easier to define game objects and particles used in particle systems. Without types, you would have to use multiple variables :
; A simple game object stored in multiple variables
object1X# = 10
object1Y# = 10
object1Life = 50
This would be fine if you only had one or two game objects. However, when you have hundreds, it is easier to define the game objects as types and then create an array using the type.
; A simple game object as a type
Type TPObject
x#
y#
life
EndType
; create array using the type
Dim objects( 400 ) As TPObject
Once the array has been created, you can manipulate each game object like this :
; set up the first game object
objects( 1 ).x# = 10
objects( 1 ).y# = 10
objects( 1 ).life = 50
; set up the second game object
objects( 2 ).x# = 10
objects( 2 ).y# = 10
objects( 2 ).life = 50
Because the game objects are stored in an array, you can easily set up all of them quickly with a {{For loop.
; set up all game objects randomly
; get screen dimensions
screenWidth = GetScreenWidth()
screenHeight = GetScreenHeight()
; set every game object
For i = 1 to 400
objects( i ).x# = RndRange( 0, ScreenWidth )
objects( i ).y# = RndRange( 0, ScreenHeight )
objects( i ).life = RndRange( 1, 50 )
Next
Related Pages
Backlinks
These pages link back to this page. You may find them helpful.
Links
- Strucs at the Basic4GL Wiki
- Types at the thinBasic Wiki
Ask a Question
Ask a question about types.