Types

Started by Mikey, November 06, 2018, 01:01:25

Previous topic - Next topic

Mikey

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.


Matty


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

Mikey

#2
@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?

Matty

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.


Mikey

@Fairgood: Thanks for that reference. It's much more complex than the manual.

Mikey

I see the information on indexing I read elsewhere that there is literature on square backets?

[]

Does anyone have a link to that information?

RemiD

#7
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

Mikey

@remiD: Thanks for that information. It's not documented anywhere. In fact the original BB book never mentions BB arrays at all.

RemiD

#9
@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 : http://rd-stuff.fr/blitz3d/blitz3d-docpak-1.99.zip