problem with types, i'm officially confused

Blitz3D Forums/Blitz3D Programming/problem with types, i'm officially confused

OK i was going through some posts and saw a solution to a problem the other day, and it made me go check on an old piece of code. in checking the old piece of code, i found that the problems was not the same as in the post but i still tried to fix it. i have "pruned" my code and tried fixing it several ways but i cant get it to work. here it is:

Function updatepickup()
For o.pickup=Each pickup
For p.player=Each player
 If EntityCollided (p\e,pikup)
  o\active=True
  ;FreeEntity o\e
 End If

  If o\kind=3 And o\active=False TurnEntity o\e,1,2,1;if its a health pack and its not used, make it spin


  If o\kind=1 And o\active=True;if the player has run into a cloaking power-up
  	
			;ON
			o\life=o\life-1  ;count down the cloaking counter  
			If o\life>1 ;if time is not up
			EntityAlpha p\e,.1 ;set alpha to see-through
			p\state=1 ;set state to on
			;OFF
			Else If o\life<1 ;if "dead"
			EntityAlpha p\e,1 ;set alpha to opaque
			p\state=0 ;set state to off
			Stop
			End If
			Delete o

  ElseIf o\kind=2 And o\active=True
    
			o\life=o\life-1;count down the "x-ray" counter
			If o\life>1;if time is not up
			WireFrame True;turn on "x-ray vision"
			Else If o\life<1;if "dead"
			WireFrame False;turn off "x-ray vision"
			End If
			Delete o
			
  ElseIf o\kind=3 And o\active=True
			
			If p\hp<3
			p\hp=p\hp+1
			End If
			Delete o
		End If
  
  

Next
Next

End Function

what happens, is that when i run into my power-up, its supposed to activate a timer and do a certain effect. the part i can't get to work is the removal of the one object. what happens right now is that it activates and then it deletes all the other power ups any help would be nice.

May i suggest you using a timer based on millisecs()

Timer = millsecs()
Time_duration = 1000 ; one whole second

repeat


until millisecs() > timer + time



That's the basic idea behind a timer. It doesn't rely on frames per second.

I'm looking at your code.

This line:

If EntityCollided (p\e,pikup)


Your not checking against each type object, mearly the same mesh over and over again. This may be causing a problem, as it would be testing all pickup objects, against the one health pickup, so if the player hits into this one pickup, they all will get deleted. I can't test it as i'm at work though, but i'm sure that's your problem.

If EntityCollided (p\e,o\e)


Should work?

thank you, I knew it would probably be something simple.

Well, actually - that won't work. EntityCollided's second parameter is the entitytype, not the entity itself.

What you need to identify is which pick up a player has collided with.

for c = 1 to countcollisions( p\e )
   if collisionentity( p\e, c ) = o\e
       o\Active = true
   endif
next


There are better and more efficient ways of handling this - specifically using the object and handle commands. It saves you iterating through them all to find the one collided with. e.g.

When you create your pickup instance ..

o.pickup = new pickup
o\e = createcube()
nameentity o\e, handle( o )


To determine which pickup the player has collided with

Entity = entitycollided( p\e, pikup )
if Entity > 0
     o.pickup = object.pickup( entityname( Entity ) )
     o\Active = true
     ;other stuff
endif


Thank you Stevie G, I didn't know how to use the object and handle commands. They really need to be documented. I'll try this solution.

object and handle commands. They really need to be documented

Here Here!!!

Mortis showed me this site a few months ago:

http://www.hpquest.com/techlord/apps/AOBPwB3D/