November 17, 2018, 01:59:20 PM

Author Topic: Types  (Read 215 times)

Offline Mikey

  • Jr. Member
  • **
  • Posts: 54
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: 566
    • 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: 54
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: 566
    • 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: 54
Types
« Reply #5 on: November 09, 2018, 12:38:22 AM »
@Fairgood: Thanks for that reference. It's much more complex than the manual.