I made a test script that only contains the two functions that are provoking the error to debug only this part of my code

I also ripped out all irrelevant level and car code to make sure these parts are the only ones invloved in the error

I heavily commented the remaining code so you can understand everything I am trying to do easily

Code:
#include <acknex.h>
#include <default.c>
#include <mtlFX.c>

//TEST CARS
ENTITY* TEST_Car;
ENTITY* TEST_CarInFront;
//TEST CARS


void LoadCarVariables(var MyCar, var OtherCar, int Speed)
{
	ENTITY* TargetCar; //CAR I WANT TO LOAD VARIABLES INTO
	ENTITY* CarInFront; //POINTER TO CAR IN FRONT Forced to NULL for testing purposes to test only when the first car is created and there is no car on front of it
	TargetCar=ptr_for_handle(MyCar); //LOAD POINTER TO CREATED CAR
	CarInFront=ptr_for_handle(OtherCar); //LOAD POINTER TO CAR IN FRONT
	
	TargetCar.skill1 = handle(CarInFront); //PASS POINTER of the car in front into skill1 of the new car we just created
	TargetCar.skill2 = Speed; //Just an example of passing another variable to the new car we just created
	set(TargetCar,FLAG1); //To tell the car we just created that it's variables are loaded and ready
}

action CarAction()
{
	reset(my,FLAG1); //Make sure flag1 is not set, to indicate my variables are not loaded yet
	
	while(!is(my,FLAG1)) //TO FORCE THE REST OF THE ACTION TO NOT RUN UNTIL MY VARIABLES ARE LOADED
	{
		wait(1);
	}
	//AFTER FLAG1 INDICATES VARIABLES ARE LOADED START DOING STUFF


	ENTITY* InFrontOfMe; //A POINTER TO THE CAR THAT IS IN FRONT OF THIS ONE
	InFrontOfMe = ptr_for_handle(my.skill1); //Load handle of car in front into pointer
	
	int MyCarFits = 0; //variable for waiting till the new car fits behind the car in front

	while(1)
	{
		if(is(my,FLAG1)) //ONLY DO STUFF IN MY WHILE LOOP IF VARIABLES HAVE BEEN LOADED
		{
			if(MyCarFits==0) //IF MY CAR DOES NOT FIT CHECK IF IT DOES
			{
				
				if(InFrontOfMe)//	IF THERE IS A CAR IN FRONT CHECK IF I FIT IN THE SPACE BETWEEN US
				{
					if(abs((vec_dist(vector(my.x,my.y,0),vector(InFrontOfMe.x,InFrontOfMe.y,0)))) > (abs(InFrontOfMe.min_x)+(abs(my.max_x))))//si el de delante se ha alejado suficiente
					{
						MyCarFits=1;
					}
				}
				else //IF THERE IS NO CAR IN FRONT (I am the first car created) THEN ASSUME THAT I MUST BE ABLE TO FIT
				{
					MyCarFits=1;
				}
			}
			else //IF MY CAR ALREADY FITS THEN START MOVING (the variable loaded into skill2 controls the speed)
			{
				c_move(me,vector(my.skill2 * time_step,0,0),nullvector,IGNORE_PASSABLE);
				//DELETED ALL IRRELEVANT CAR CODE AND JUST LEFT MOVEMENT FOR TESTING PURPOSES
			}
		}
		
	}
	wait(1);
}


void main()
{
	//BASIC LOAD INSTRUCTIONS ONLY FOR TEST
	video_switch(8,0,1);
	level_load("Ciudad.wmb");
	//BASIC CAMERA FOR TESTING WITH A GOOD TOP VIEW OF THE STREET
	vec_set(camera.x,vector(-1043.581,-40.077,752));
	vec_set(camera.pan,vector(-4.269,-35.397,0));
	wait(1);


	TEST_CarInFront=NULL; //FORCE TEST WHEN THERE IS NO CAR IN FRONT... If this is the first car created the car in front pointer will be null
	TEST_Car=ent_create("JESUS.mdl",vector(0,0,32),CarAction); //Create first car
	LoadCarVariables(handle(TEST_Car),handle(TEST_CarInFront), 3); //Load first car's variables with no car in front

	while(1)
	{
		//DELETED ALL IRRELEVANT LEVEL CODE TO ONLY TEST WHAT IS PROVOKING THE ERROR
		wait(1);
	}
}



The game starts and I get these two errors
Quote:
ERROR E1514:
invalid pointer or handle in ActionCar

Quote:
ERROR E1513:
crash in ActionCar

After I accept the two errors the level loads fine and the car is created but does not move

Does anybody have an idea of what I am doing wrong?


"The more you know, the more you realize how little you know..."

I <3 HORUS
http://www.opserver.de/ubb7/ubbthreads.php?ubb=showflat&Number=401929&page=1