VERY easy problem with types

Blitz3D Forums/Blitz3D Beginners Area/VERY easy problem with types

(tu) ENAY(Posted 2004) [#1]
I'm such a dumb ass.

I've got me type structures and it's all working nicely. Except I can't seem to figure out how to make an array of types.
For example I have


arse.moo = New moo


I want to have more arses.

For example something like this:-

Dim arse(10)

arse(0).moo = New moo
arse(1).moo = New moo
etc

so I therefore have 10 moo data types contained within arse.
Yet somehow I just can't seem to figure it out.

HELP ME! ;)


semar(Posted 2004) [#2]
Dim myarse(10).moo
myarse(0).moo = new moo

It should work.

Anyway, you could use the type itself as an object containter, hence you don't really need the array, unless you want directly access to a type element by giving the array index.

If you do:
for n = 1 to 10
mymoo.moo = new moo
mymoo\field_name = n
next

You have already 10 moo elements, each with its fields. To go through the whole collection, you can:
for mymoo.moo = each moo
print mymoo\field_name
next

Sergio.


(tu) ENAY(Posted 2004) [#3]
When I was planning on doing was :-

for (int loop = 0 ; loop < 4 ; loop++ )
{
mymoo[loop].DoStuff()
}


(tu) ENAY(Posted 2004) [#4]
Oops. I mean:-

for loop = 0 to 3
mymoo(loop)\Param = mymoo(loop)\Param + 1;
next

;)


I'll give your code a try and see if it works.
Thanks mate :)


GfK(Posted 2004) [#5]
Semar's code is slightly wrong. Try this:
Dim Arse.moo(10)

For N = 0 To 10
	Arse.moo(N) = New moo
	Arse.moo(N)\Tits = Rand(4,8)
Next

Type moo
	Field Tits%
End Type

;You can retrieve info like this:
For N = 3 To 7
	DebugLog Arse(N)\Tits
Next

DebugLog ""

;...Or like this:
For A.moo = Each moo
	DebugLog A\Tits
Next



(tu) ENAY(Posted 2004) [#6]
Dave! You're the man. I especially like your Tits ;)