How could i do this?

Blitz3D Forums/Blitz3D Programming/How could i do this?

Ash_UK(Posted 2005) [#1]
I would like to have my AI cars able to overtake other cars. I have them all stored in a type call "opp" (for opponent)
But if i type:

for o.opp = each opp
if entitydistance(o\entity,?)<5 then 
moveentity o\entity,-o\speed,0,0
next


Obviously, the reason i've typed the "?" above, shows that i didn't have a clue how to access a check on all other cars within that type :(

I would be delighted if someone could help me out here :)

Thanks


Baystep Productions(Posted 2005) [#2]
Umm, maybe

for o2.opp = each opp
  for o.opp = each opp
   if entitydistance(o\entity,o2\entity)<5
     moveentity o\entity,-o\speed,0,0
   endif
  next
next


But I haven't tried that, just looking at it.


Ash_UK(Posted 2005) [#3]
hmmm, i'll give that a try :)
Cheers man!!


Ash_UK(Posted 2005) [#4]
You PCD GUY....are a STAR!!!!! :D
It works!!!! Thankyou so very very much

Thanks again :D


Picklesworth(Posted 2005) [#5]
It's more tidy to dump that check in a seperate function, too.

for o.opp = each opp
	myFunction(o.opp)
next

function myFunction(o.opp)
	for o2.opp = each opp
		If entitydistance(o2\entity,o\entity)<5
			moveentity o2\entity,-o2\speed,0,0
		endif
	next
end function


Depends on your tastes, though.


Ash_UK(Posted 2005) [#6]
Hmmm, any advice is greatly appriciated :D
I shall give that one a whirl
Thanks Mr Picklesworth :)


octothorpe(Posted 2005) [#7]
Ensure that o <> o2.