Multiple TYPE's ?

Blitz3D Forums/Blitz3D Beginners Area/Multiple TYPE's ?

Rhyolite(Posted 2003) [#1]
I am new to the communtity so first off a big HELLO and thanks for all your help which I have already got from searching these forums :o)

However I can not work this one out or find anything in forums. I am probabaly confused and missunderstanding the TYPE command but here goes....

(Oh, and I may be using the word 'collections' in the wrong context??)

I would have thought you should be able to have multiple collections of the same TYPE e.g. create a SOLDIER TYPE and then have a number of GOOD.SOLDIER's and loads of ENEMY.SOLDIER's. Both these collections use the same TYPE (and its associated fields) but should be distinct from each other???

But this does not appear to be the case (to me at least). All the commands for moving through collections actualy move you through all objects of that TYPE, so their is no way to isolate your GOOD soldiers and your ENEMY soldiers.

I have no problem with this 'limitation', it just means I would have to create a GOODSOLDIER TYPE and an ENEMYSOLDIER TYPE. But then why does Blitz3D allow me to create different collections of the same TYPE???

Why bother with
'Enemy.Soldier=New Soldier'
why not just have
'New Soldier'

and again why have
'Good = After Good'
instead of
'Next Soldier' or similiar

I think I must be missing something here or doing something wrong? Please can someone explain. I have included a bit of code I used to test this myself.

Thanks in advance, Rhy :o)



--------- MY EXAMPLE CODE ----------

Graphics 640,480

Type Test
Field Name$
End Type

Global BigCount=0

While Not KeyHit(1)

;add to first collection
For p=1 To 2
Primary.Test=New Test
Primary\Name=p
Next
BigCount=BigCount+2
;display first(?) collection
Primary.Test=First Test
For i=1 To BigCount
Print"Primary Name "+i+" = "+Primary\Name
Primary=After Primary
Next
Print
WaitKey()

;add to second collection
For s=100 To 200 Step 100
Secondary.Test=New Test
Secondary\Name=s
Next
BigCount=BigCount+2
;display second(?) collection
Secondary.Test=First Test
For i=1 To BigCount
Print"Secondary Name "+i+" = "+Secondary\Name
Secondary=After Secondary
Next
Print
WaitKey()

Wend

End


dynaman(Posted 2003) [#2]
> 'Enemy.Soldier=New Soldier'

This line is not creating a new collection, but a new instance of the soldier collection, it is then creating a pointer to that instance and storing it in the enemy variable.


Stevie G(Posted 2003) [#3]
If good and bad soldiers share the same attributes all you need to do is add another field in the type such as

field is_good

Then when you itterate through the type instances like so you can determine which is which ...

for l.soldier = each soldier

if l\is_good
{do good soldier stuff}
else
[do bad soldier stuff}
endif

next


Henrik(Posted 2003) [#4]
;Try this


Graphics 800,600

Type soldier
Field good_x,good_y,bad_x,bad_y
End Type

For count=0 To 30
s.soldier=New soldier
s\good_x=30+count
s\good_Y=count*20
s\bad_x=600-count
s\bad_y=count*20
Next


Updatesoldier()
WaitKey()
end

Function Updatesoldier()
For s.soldier=Each soldier
Text s\good_x,s\good_y,"good soldier"
Text s\bad_x,s\bad_y,"bad soldier"
Next
End Function


Rhyolite(Posted 2003) [#5]
Aha, I think I have got it now - thanks :o)

Just spent 20 minutes messing with TYPES again and it seems to make sense now that I understand the 'variables' are pointers to an element of a single 'collection' of the TYPE. Also, the 'collection' is global but the pointers may be LOCAL or GLOBAL - neat!

Hmmm, not sure if I explained that very well - but I seem to understand it now. Cheers all, Rhyo :o)


dynaman(Posted 2003) [#6]
Sounds like you have it 100% correct now.