Im new, also need help with types

Blitz3D Forums/Blitz3D Beginners Area/Im new, also need help with types

Kiyoshi(Posted 2010) [#1]
Well, I've been a member of the forum for a little while, and I've looked through the forums and code archives to find what I need. But alas, I couldnt find what I needed this time, so I decided to make myself known.

So first thing I want to say hi, obviously this is my first post. The community here seems nicer than any other forum I've joined, so I hope my time here will be memorable :) Also, I want to tell you what kind of experience (not much!) I've had, so you don't give me a complex piece of code that I would'nt understand at this time.
So, I've toyed around with blitz3d for about a year now, and didnt really get anywhere, but now I've decided to really get into programming. I first started when I found the book "3d game programming for teens" at my library, so that taught me most of what I know. Also, I learned a very few other things just by playing with different commands. Basically, I can create a world by loading meshes and creating shapes, I know how to work functions, and global variables, if/then commands, all that good stuff. And of course the wend/while loop, which is what I use. Very recently I started using functions for moving objects (keydown(17)=move player), instead of just putting it in my wend/while loop.
Ok, so here's what I need help with, types. I need to know how to select and manipulate a specific type object. For example, lets say I create 20 monsters using types (type monster) along with a for/next statment, and during my game, I want to place a specific monster (say, monster 4 of the 20) at a certain position. I know how to use for/each to move all the monsters at once, but I just want to move monster 4. Could someone give me a line of code or two, to help me out? Thanks!


Charrua(Posted 2010) [#2]
hi, welcome

there are more than one aproach, one would be:
to have a field Number in each type variable

type tMonster
field Number
field your other fields...
end type

and then in the for/each loop test

if Monster\Number=4 then
;modify only that Monster
Exit ;should be good to exit the for/each loop because you don want to precess another Monster
end if


testing for some atrribuetes (i.e a moster with that number o which Life is more or less than, or position, or time, or distance, whatever) inside the for/each loop helps you to get control of specifics objects on the type list.

hope you understand my english

Juan


PowerPC603(Posted 2010) [#3]
You know how to use arrays?
Then you could create an array to hold all your monsters and just pick the one you need:
; Setup the monster type declaration
Type Monster
	Field X, Y
	Field Model
End Type

; Create an array to hold all Monsters
Dim ArrayMonsters.Monster(20)

; Create 20 monsters and link them to the array
For i = 1 To 20
	ArrayMonsters(i) = New Monster
Next



; Get the fourth monster
m.monster = ArrayMonsters(4)


Using this example, you can still loop through all monster types using the For-Each loop to process all monsters at once, because the monster type-instances are created globally and are internally added to a global list.
The array is declared to hold the reference to the monster types (note the ".Monster" behind the name of the array).


Kiyoshi(Posted 2010) [#4]
Thanks, these both work awesome! Now back to programming.... :D


Drak(Posted 2010) [#5]
Heres a simple example: