|
1 registered members (AndrewAMD),
599
guests, and 3
spiders. |
|
Key:
Admin,
Global Mod,
Mod
|
|
|
Re: Entity Action with parameters
[Re: Lukas]
#322413
05/06/10 19:09
05/06/10 19:09
|
Joined: Oct 2008
Posts: 513
Carlos3DGS
OP
User
|
OP
User
Joined: Oct 2008
Posts: 513
|
Thankyou, I didnot understand it correclty the first time. By the way... How to make sure an entity exists in an if statement? I think this is where my function is crashing: if(PreviousCar!=NULL)//If there exists a previous car or I am the first PreviousCar is an entity declared like this: And before that function is called it is initialized as: The crash gives me Error E1514 so I think it must be related to that Error E1514: Invalid pointer or handle An engine function, like handle or ptr_for_handle, was called with an invalid pointer or handle. Does anyone know what I am doing wrong?
|
|
|
Re: Entity Action with parameters
[Re: Carlos3DGS]
#322418
05/06/10 20:03
05/06/10 20:03
|
Joined: Dec 2006
Posts: 1,086 Queensland - Australia
Nidhogg
Serious User
|
Serious User
Joined: Dec 2006
Posts: 1,086
Queensland - Australia
|
Have you added PreviousCar = me in your script before checking if(PreviousCar!=NULL)
Windows XP SP3 Intel Dual Core CPU: E5200 @ 2.5GHz 4.00GB DDR3 Ram ASUS P5G41T-M LX PCIE x16 GeForce GTS 450 1Gb SB Audigy 4 Spyware Doctor with AntiVirus
|
|
|
Re: Entity Action with parameters
[Re: Nidhogg]
#322435
05/06/10 21:59
05/06/10 21:59
|
Joined: Oct 2008
Posts: 513
Carlos3DGS
OP
User
|
OP
User
Joined: Oct 2008
Posts: 513
|
More or less... I added it but it dosent point to me PreviousCar = ptr_for_handle(my.skill1); But if it is the first car created then previouscar is still NULL because it dosnt have anything to point to yet. Thats why I want something to detect if it is already a valid pointer or not. something like if(PreviousCar!=NULL) But for some reason that does not work properly
|
|
|
Re: Entity Action with parameters
[Re: DJBMASTER]
#322451
05/07/10 03:31
05/07/10 03:31
|
Joined: Jul 2008
Posts: 1,178 England
MrGuest
Serious User
|
Serious User
Joined: Jul 2008
Posts: 1,178
England
|
is your PrevCar a local or global entity? (where about do you declare it in your code) NB: instead of
ENTITY* PrevCar;
PrevCar = NULL;
you can just use
|
|
|
Re: Entity Action with parameters
[Re: MrGuest]
#322613
05/08/10 12:53
05/08/10 12:53
|
Joined: Oct 2008
Posts: 513
Carlos3DGS
OP
User
|
OP
User
Joined: Oct 2008
Posts: 513
|
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
#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 ERROR E1514: invalid pointer or handle in ActionCar 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?
|
|
|
Re: Entity Action with parameters
[Re: Carlos3DGS]
#322621
05/08/10 14:12
05/08/10 14:12
|
Joined: Jul 2008
Posts: 1,178 England
MrGuest
Serious User
|
Serious User
Joined: Jul 2008
Posts: 1,178
England
|
once you get an error for a function, that function will end and will not run again until called the error occurs by the engine starts by calling in main you have
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
LoadCarVariables(handle(TEST_Car),handle(TEST_CarInFront), 3); //Load first car's variables with no car in front
which will obviously error as you have a handle pointing to NULL which is ERROR 1514
|
|
|
Re: Entity Action with parameters
[Re: MrGuest]
#322635
05/08/10 15:45
05/08/10 15:45
|
Joined: Oct 2008
Posts: 513
Carlos3DGS
OP
User
|
OP
User
Joined: Oct 2008
Posts: 513
|
Modified script to check before I use handle(), now I dont get errors but it just seems to not do anything now... Mabe it gets caught in an infinite loop?
#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
TargetCar=ptr_for_handle(MyCar); //LOAD POINTER TO CREATED CAR
TargetCar.skill1 = OtherCar; //Load handle to car in front, if there was no car in front I should have recieved a 0
TargetCar.skill2 = Speed; //Just an example of passing another variable to the new car we just created
TargetCar.skill6=1; //To tell the car it has it's variables loaded and ready
}
action CarAction()
{
my.skill6=0;//Make sure skill6 is "0", to indicate my variables are not loaded yet
ENTITY* InFrontOfMe; //A POINTER TO THE CAR THAT IS IN FRONT OF THIS ONE
int MyCarFits = 0; //variable for waiting till the new car fits behind the car in front
wait(1);
while(1)
{
if(my.skill6==1) //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 (my.skill1!=0) //if there was no car in front I should have recieved "0" so I load pointer as NULL, if there was then load the handle into my InFrontOfMe pointer
{
InFrontOfMe = ptr_for_handle(my.skill1); //Load handle of car in front into pointer
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,0);
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
if(TEST_CarInFront) //if it is not null pass the handle, if it is null pass 0
{
LoadCarVariables(handle(TEST_Car),handle(TEST_CarInFront), 3); //Load first car's variables with handle to car in front
}
else
{
LoadCarVariables(handle(TEST_Car),0, 3); //Load first car's variables with no car in front "0"
}
while(1)
{
//DELETED ALL IRRELEVANT LEVEL CODE TO ONLY TEST WHAT IS PROVOKING THE ERROR
wait(1);
}
}
EDIT: Ok, I added breakpoints all over the place and it seems to get caught in the CarAction while loop forever as if skill6 was never==1 and it never returns to the main function to call the LoadCarVariables() function Anyone know why?
|
|
|
Re: Entity Action with parameters
[Re: Carlos3DGS]
#322651
05/08/10 17:06
05/08/10 17:06
|
Joined: Apr 2006
Posts: 737 Ottawa, Canada
Ottawa
User
|
User
Joined: Apr 2006
Posts: 737
Ottawa, Canada
|
Hi! I'm looking at your code. Here's what I found so far. action CarAction() { my.skill6=0;//Make sure skill6 is "0", to indicate my variables are not loaded yet ENTITY* InFrontOfMe; //A POINTER TO THE CAR THAT IS IN FRONT OF THIS ONE int MyCarFits = 0; //variable for waiting till the new car fits behind the car in front
Entities should not be declared in an Action. This would make them a local What you need is a global entity, so declare it outside the function
Hope this helps! Ottawa  Ver 7.86.2 Pro and Lite-C
|
|
|
Moderated by mk_1, Perro, rayp, Realspawn, Rei_Ayanami, rvL_eXile, Spirit, Superku, Tobias, TSG_Torsten, VeT
|