Types scan
Blitz3D Forums/Blitz3D Programming/Types scan
| ||
..this is how im creating different types of enemies.. if EnemyType=1 Troll.enemy=new enemy Troll\ID=something Troll\Life=something . . end if if EnemyType=2 Gryphon.enemy=new enemy Gryphon\ID=something Gryphon\Lige=something . . end if so..when I actually passing trough Troll type collection, like For Troll.enemy=each enemy ;do stuff here and change some fields within type . . . next i noticed that, actually, eventual changes, regarding gameplay conditions, affecting also type collection Gryphon in sense that I have been selected to pass trough Troll collection but i have noticed that actually given structure passing trough Gryphon collection too..or actually anything i have been stored in 'enemy' type..is this okay?? I mean, I thought by naming type collection wity Troll.enemy or Gryphon.enemy, they are separated and requiring separate access(what i wanted)...or im doing something wrong here? |
| ||
I thought by naming type collection wity Troll.enemy or Gryphon.enemy... There is only one collection for the user defined type "enemy". Troll and Gryphon are not collections. They are simply two variables of type enemy. |
| ||
..ohh..I see..so what would be best way to pass trough specific variables of type enemy, while ignoring others respectively? |
| ||
..I mean..im confused because i use to update and play only with Troll\<whatever field here> , but its affecting Gryphon\<whatever field here> too, so, whats the difference then by giving them different names if they are going to be updated all, no matter wich one im calling in update? |
| ||
You're not giving them different names, you're just creating a variable. It's no different from saying: For Even=0 to 9 Print Even Next And For Odd=0 To 9 Print Odd Next They're both going to print the same thing. Just because you called the variables something different doesn't change anything. If you only want to update enemies of a certain type, you're going to need to have a field within the type which stores the type of the enemy, and then check it when updating. Const ENEMYTYPE_GRIFFON=1 Const ENEMYTYPE_TROLL=2 For MyEnemy.Enemy=Each Enemy If MyEnemy\Type=ENEMYTYPE_GRIFFON End If If MyEnemy\Type=ENEMYTYPE_TROLL End If Next Etc. I should possibly point out that BlitzMax would make this much easier, as it not only allows you to create your own collections of objects so you could have a list for each enemy type, but it also features inheritance, so you could have trolls and griffons extend a base enemy type, allowing you to cycle through a list of all enemies and still only pick out the enemies of a certain type. |
| ||
..i see...now its very clear..thanks Gabe.. |