News:

PlayBASIC2DLL V0.99 Revision I Commercial Edition released! - Convert PlayBASIC programs to super fast Machine Code. 

Main Menu

Drawing a Checker Board I never use TYPES

Started by baggey, June 05, 2018, 02:29:42 AM

Previous topic - Next topic

baggey

Hi,

After a recent post finally types! has reared its ugly head. I haven't had types explaind enough as to why we need to use or have them?

Im using the Checker board as i can visualize something happening with the type! Found in Sources.



  Type Tiles
       Xpos    ; X coord of tile
       Ypos    ; Y coord of tile
       Colour  ; Colour of this Tile
  EndType


; Dimension an 2D Typed array called Board
 Dim Board(10,10) as Tiles



So the type is away of having a name with other parts attached which to me would be a DIm ()
in the above code further on in the program there is no mention of tiles or type?

So why cant it just be?



Dim Board (10,10)
       Xpos    ; X coord of tile
       Ypos    ; Y coord of tile
       Colour  ; Colour of this Tile
  EndType


I sort of get the idea of neatly putting things together. in a DIM()

Ie, 50 space Invaders all with
color, dead, shape1, shape,2 ,xpos, ypos, strength, etc

Rather than remembering which box in the array was the above.  It seems like a neat way of declaring a 3 x Dim(x,y,z) But with the Z part having a useful name to access it.

So for me trying to understand the concept. Ie for a space invader why could't we have



Type invader(5,10) ; 5 rows of 10 invaders
   color
   dead
   shape1
   shape2
   xpos
   ypos
   strength


or just plain simply do away with type and change to  :-[



Dim invader(5,10) ; 5 rows of 10 invaders
   color
   dead
   shape1
   shape2
   xpos
   ypos
   strength


or even


Dim invader(5,10) ; 5 rows of 10 invaders

   color, dead, shape1, shape2, xpos, ypos, strength


And not bother with types! I know theres something under lying or pinning as to why it all needs to be setup maybe in that way OR DOES IT?

Would make a load more sence for a beginner or someone learning the concept of Programming.   ???

or maybe a new command request for Play Basic? Cutting straight to the chase. So to speak?


Anyway with a Sigh and a Laugh. Someone is probably going to try and explain it to me. So the penny drops?

But surely the last piece of code makes a lot more sence to comprend. No mention of types or "CLASS" dare i say it.

I never use types in my programs as i don't fully understand them! Is there a speed gain in accesing the variables as well?

Kind Regards BaggeyError Missing Closing Square Bracket
Jesus was only famous because of his dad

kevin


Quote

So why cant it just be?

PlayBASIC Code: [Select]
Dim Board (10,10)
Xpos ; X coord of tile
Ypos ; Y coord of tile
Colour ; Colour of this Tile
EndType






   a nameless structure couldn't be used else where, like in another array/variable/list or via pointer or function /psub parameter for example.  It's like having a function with no name.. how would you call it ? 
   
   well, in terms of parsing, anything can be parsed, but in your example you'd need an opening type so the block can be determined, otherwise it'd just random tokens following the Dim