type question

Blitz3D Forums/Blitz3D Programming/type question

Stevie G(Posted 2003) [#1]
This is not a strong point so forgive the explanation.

I have 10 objects of type .player but only the last 2 objects need to be referrenced in terms of human control,camera position etc.. Each object has a 'field' called 'human' which is used to identify whether the object is human controlled or cpu controlled. This can be -1(CPU), 0 = player1 or 1=player2.

In my program I have to constantly iterate through the type and only do something when var\human >-1. I've no doubt that there's a better way of doing this - can anyone help?


Shambler(Posted 2003) [#2]
Sounds like 2 of your types are so different from the others, maybe you could make another type just for the 2 players to save iterating through all 10 objects.

I think it's more of a design issue than anything else, you aren't going to be losing much in terms of speed just for looking through the 10 types.

Leave it as it is or make another type the choice is mainly a preference rather than anything else.


Binary_Moon(Posted 2003) [#3]
or you could assign them to two global variables and just reference them. Or you could assign the types to an array and just use the last two in that to reference them.


(tu) sinu(Posted 2003) [#4]
"or you could assign them to two global variables and just reference them. Or you could assign the types to an array and just use the last two in that to reference them. "

stick to the first suggestion, it's the easiest way for you.


Stevie G(Posted 2003) [#5]
Thanks for the advice. As the human controlled objects have more or less the same properties as the other 8 it would be too much hastle changing the code to accomodate a new type with a couple less fields. I think I'll just leave as is - just wanted to tidy up the code a bit.


NewtSoup(Posted 2003) [#6]
Here's a possible solution:
Dim players.player(8)
for f= 1 to 8
   players(f)=create_player()
next

player1.player=create_player()
player2.player=create_player()

now you have a distinct array of computer controlled "players" and 2 references to the human controlled "players"


problem solved.

- Luke :)