January 18, 2019, 12:25:43 AM

Author Topic: Types  (Read 486 times)

Offline Mikey

  • Jr. Member
  • **
  • Posts: 63
Types
« on: November 06, 2018, 01:01:25 AM »
I'm trying to move through a type array without using the FOR command.
I need to know when I'm at the end of the list.
Using FOR, the loop just stops when it's over but I'm using BEFORE and AFTER where necessary.


Offline Matty

  • Hero Member
  • *****
  • Posts: 584
    • MattiesGames
Re: Types
« Reply #1 on: November 06, 2018, 04:30:56 AM »
Code: [Select]
type mytype
field x,y
end type

m.mytype = new mytype
m\x = 1
m\y = 1
m.mytype = new mytype
m\x = 2
m\y = 2

;with for loop
debuglog "for loop"
for a.mytype = each mytype
debuglog a\x + " " +a\y
next
;with after/before
debuglog "after before"
a.mytype = first mytype
while(a<>null)
debuglog a\x + " " + a\y
a.mytype = after a
wend

Offline Mikey

  • Jr. Member
  • **
  • Posts: 63
Types
« Reply #2 on: November 07, 2018, 11:04:44 PM »
@Matty:
Thanks for the code. I see that I never knew to check for a NULL or that there was a NULL to check when using types.

One thing still confusing is where, or how, you defined the:
a.mytype
without using:
a.mytype = NEW TYPE

Is this something undocumented like square brackets?

Offline Matty

  • Hero Member
  • *****
  • Posts: 584
    • MattiesGames
Re: Types
« Reply #3 on: November 08, 2018, 01:18:46 AM »
regarding defining a.mytype....

when we declare variables we can declare them as

# floating point
% integer
or $ string

eg a$ = a string
eg a% = an integer

however we can also declare a variable as a custom-type (which you can think of as another data type like integers and strings but much more complex)

therefore you'd declare it as

a.[type name]

It will of course be 'null' at that point.

In my code above I set it to the 'first' [type name]....you could also set it to the 'last' as well.

There is documentation in blitz3d that is very thorough about types - have a read through and play around with it.

Offline fairgood

  • Jr. Member
  • **
  • Posts: 20
Re: Types
« Reply #4 on: November 08, 2018, 07:01:05 AM »

Offline Mikey

  • Jr. Member
  • **
  • Posts: 63
Types
« Reply #5 on: November 09, 2018, 12:38:22 AM »
@Fairgood: Thanks for that reference. It's much more complex than the manual.

Offline Mikey

  • Jr. Member
  • **
  • Posts: 63
Types
« Reply #6 on: November 29, 2018, 08:30:23 PM »
I see the information on indexing I read elsewhere that there is literature on square backets?

[]

Does anyone have a link to that information?

Offline RemiD

  • Hero Member
  • *****
  • Posts: 797
Re: Types
« Reply #7 on: November 29, 2018, 09:15:37 PM »
some explanations that you may find useful about customtypes :
http://mojolabs.nz/posts.php?topic=104279

[] are used for local arrays
() are used for global arrays

and you can also create arrays in a customtype
Type Thing
 Field Truc%[100]
end type

t.Thing = new Thing
t\Truc[1] = 33

something like that
DualCore AMD E-450, 1646 MHz - 6 Go DDR3 1333 SDRAM - AMD Radeon HD 6320 Graphics (384 Mo) - Windows 7 Home Premium - DirectX 11.0

Offline Mikey

  • Jr. Member
  • **
  • Posts: 63
Types
« Reply #8 on: November 30, 2018, 12:23:54 AM »
@remiD: Thanks for that information. It's not documented anywhere. In fact the original BB book never mentions BB arrays at all.

Offline RemiD

  • Hero Member
  • *****
  • Posts: 797
Re: Types
« Reply #9 on: November 30, 2018, 04:15:44 PM »
@Mikey>> ;)

in case you don't know, there was another docpak (1.99) which contains additional infos / examples, not sure if it was released with the last version of Blitz3d.

a copy here : rd-stuff.fr/blitz3d-docpak-1.99.zip
DualCore AMD E-450, 1646 MHz - 6 Go DDR3 1333 SDRAM - AMD Radeon HD 6320 Graphics (384 Mo) - Windows 7 Home Premium - DirectX 11.0