ptr_for_handle (handle);

Returns a pointer to the object identified by the given handle. This way arbitrary objects can be stored in a save-proof way in entity skills or variables.

Parameters:

handle - handle of an object

Returns:

Pointer to the object, or NULL if the handle was invalid. In the latter case a warning is issued when warn_level is at 2 or above.

Speed:

Medium

Example (lite-C):

// control a gun with the camera
function use_gun()
{
// create a laser spot model	
	ENTITY* laserspot = ent_create ("target.mdl",NULL,NULL); 
	set(laserspot,PASSABLE|BRIGHT); // the target model is passable
	laserspot.ambient = 100; // and should look bright enough

	while (1)
	{
// calculate the target vector
		VECTOR trace_target;
		vec_set(trace_target,vector(5000,0,0)); // the weapon has a firing range of 5000 quants
		vec_rotate(trace_target, camera.pan);
		vec_add(trace_target, camera.x);
		
// display the red laser spot at the target position
		if (c_trace(camera.x,trace_target, IGNORE_PASSABLE | USE_POLYGON| SCAN_TEXTURE) > 0) // hit something?
		{	
			reset(laserspot,INVISIBLE);
			vec_set(laserspot.x,target);
			vec_fill(laserspot.scale_x,minv(6,vec_dist(target,camera.x) / 500)); // adjust the laser spot size
		} else
			set(laserspot,INVISIBLE);
					
		var laserspot_handle = handle(laserspot);
wait(1); // store the laserspot entity pointer in a handle for being save-proof laserspot = ptr_for_handle(laserspot_handle); } }

See also:

handle, ptr_first, game_save

► latest version online