|
1 registered members (AndrewAMD),
599
guests, and 3
spiders. |
|
Key:
Admin,
Global Mod,
Mod
|
|
|
Re: Entity Action with parameters
[Re: Carlos3DGS]
#322711
05/08/10 23:06
05/08/10 23:06
|
Joined: Apr 2006
Posts: 737 Ottawa, Canada
Ottawa
User
|
User
Joined: Apr 2006
Posts: 737
Ottawa, Canada
|
Hi!
I like the part about following the other car...;)
Back to your while loop in main. If the code is the same as it was in previous message... The main function never gets to call a function since the while (1) is infinite loop.
The question is ...what function should get called before your while?
Hope this helps! Ottawa  Ver 7.86.2 Pro and Lite-C
|
|
|
Re: Entity Action with parameters
[Re: Ottawa]
#322735
05/09/10 00:19
05/09/10 00:19
|
Joined: Oct 2008
Posts: 513
Carlos3DGS
OP
User
|
OP
User
Joined: Oct 2008
Posts: 513
|
I explained myself wrong, sorry. Placing several breakpoints in my script and running step by step it seems as if the while loop inside CarAction() never ends, so it never returns to main() The last line to execute in main is: TEST_Car=ent_create("JESUS.mdl",vector(0,0,32),CarAction); //Create first car Then it runs the car action and gets stuck in the while that is inside CarAction() so the next line in main (to load the variables for the car skills) never runs. So these lines in main never get executed: 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" } It is very strange, it looks like if the wait(1); instructions are complete ignored by the engine so it never returns to the calling function "main" after it starts the CarAction while loop even though it has a waut(1) instruction inside the loop
|
|
|
Re: Entity Action with parameters
[Re: Carlos3DGS]
#322737
05/09/10 00:40
05/09/10 00:40
|
Joined: Oct 2008
Posts: 513
Carlos3DGS
OP
User
|
OP
User
Joined: Oct 2008
Posts: 513
|
Ok, since this was very strange I made a very simple script to test things out, just simple counters, and debugging it with breakpoints and executing step by step with F10 int FunctionMainCounter = 0; int Function1Counter = 0; int Function2Counter = 0;
void Function1() { while(1) { Function1Counter++; wait(1); } }
void Function2() { while(1) { Function2Counter++; wait(1); } }
void main() { Function1(); Function2(); while(1) { FunctionMainCounter++; wait(1); } }
I added watch for the 3 global variables "FunctionMainCounter", "Function1Counter", and "Function2Counter". Only Function1Counter gets higher values, the other variables always stay at 0 Is this supposed to happen?
|
|
|
Re: Entity Action with parameters
[Re: Carlos3DGS]
#322738
05/09/10 00:44
05/09/10 00:44
|
Joined: Jan 2002
Posts: 300 Usa
Rich
Senior Member
|
Senior Member
Joined: Jan 2002
Posts: 300
Usa
|
I'm not sure if you found it yet, but you have youre "wait(1)" out of scope in your while(1) loop. After moving it the code no longer froze. like this: while(1) { code... } wait(1); to this: while(1) { code... wait(1); } Below is the code I used, I made some changes to the MAP and MODEL loaded since I didn't have them.
#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("level.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(CUBE_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"
ent_create(CUBE_MDL,vector(0,0,32),CarAction);
}
while(1)
{
//DELETED ALL IRRELEVANT LEVEL CODE TO ONLY TEST WHAT IS PROVOKING THE ERROR
wait(1);
}
}
Last edited by Rich; 05/09/10 01:14.
A8 com / A7 free
|
|
|
Re: Entity Action with parameters
[Re: Carlos3DGS]
#322770
05/09/10 11:40
05/09/10 11:40
|
Joined: Jan 2002
Posts: 300 Usa
Rich
Senior Member
|
Senior Member
Joined: Jan 2002
Posts: 300
Usa
|
No problem, glad I could help  . I'm surprised I caught it myself.
A8 com / A7 free
|
|
|
Re: Entity Action with parameters
[Re: Carlos3DGS]
#322771
05/09/10 11:45
05/09/10 11:45
|
Joined: Oct 2008
Posts: 513
Carlos3DGS
OP
User
|
OP
User
Joined: Oct 2008
Posts: 513
|
The partial code I ripped out of my game for testing how the pointers work is now tested with several cars and running fine. I want to thank everyone who helped me make this part of my code work by sharing it with you and everyone else interested in doing something similar. The complete code is not ready for sharing but the test code is. In the complete code the cars do much more than moving forward and they are created in a "spawning" function, selecting cars randomly from a list before creating them. What the partial test code does: Spawns several cars in a location, updates their bounding box to match their size, passes them a pointer to the previously created car, before moving calculates the size of my car and the car in front to wait till the new car fits behind the car in front.
#include <acknex.h>
#include <default.c>
#include <mtlFX.c>
//TEST CAR POINTERS
ENTITY* TEST_Car;
ENTITY* TEST_CarInFront;
//TEST CAR POINTERS
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.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
TargetCar.skill6=1; //To tell the car it has it's variables loaded and ready
}
action CarAction()
{
set(my,PASSABLE);
c_setminmax (me);
my.skill6=0;//Make sure skill6 is "0", to indicate my variables are not loaded yet
my.pan=270;
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;
reset(my,PASSABLE);
}
}
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;
reset(my,PASSABLE);
}
}
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);
//PRETEND DUMMY SPAWNING TEST
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,100),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"
}
TEST_CarInFront=TEST_Car; //Set CarInFront to the last car we created
TEST_Car=ent_create("Bus2.mdl",vector(0,0,100),CarAction); //Create second 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 second car's variables with handle to car in front
}
else
{
LoadCarVariables(handle(TEST_Car),0, 3); //Load second car's variables with no car in front "0"
}
TEST_CarInFront=TEST_Car; //Set CarInFront to the last car we created
TEST_Car=ent_create("RAUL.mdl",vector(0,0,100),CarAction); //Create third 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 third car's variables with handle to car in front
}
else
{
LoadCarVariables(handle(TEST_Car),0, 3); //Load third car's variables with no car in front "0"
}
//PRETEND DUMMY SPAWNING TEST
while(1)
{
//DELETED ALL IRRELEVANT LEVEL CODE TO ONLY TEST WHAT IS PROVOKING THE ERROR
wait(1);
}
}
Heavily commented code for easy understanding. Feel free to use and modify as you wish! Thankyou everyone!
|
|
|
Moderated by mk_1, Perro, rayp, Realspawn, Rei_Ayanami, rvL_eXile, Spirit, Superku, Tobias, TSG_Torsten, VeT
|