Gamestudio Links
Zorro Links
Newest Posts
Newbie Questions
by fairtrader. 12/05/23 14:22
Zorro Trader GPT
by TipmyPip. 12/04/23 11:34
Square root rule
by Smallz. 12/02/23 09:15
RTest not found error
by TipmyPip. 12/01/23 21:43
neural function for Python to [Train]
by TipmyPip. 12/01/23 14:47
Xor Memory Problem.
by TipmyPip. 11/28/23 14:23
Training with command line parameters
by TipmyPip. 11/26/23 08:42
Combine USD & BTC Pairs In Asset Loop
by TipmyPip. 11/26/23 08:30
AUM Magazine
Latest Screens
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Tactics of World War I
Who's Online Now
1 registered members (AndrewAMD), 599 guests, and 3 spiders.
Key: Admin, Global Mod, Mod
Newest Members
fairtrader, hus, Vurtis, Harry5, KelvinC
19019 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 3 of 3 1 2 3
Re: Entity Action with parameters [Re: Ottawa] #322705
05/08/10 22:50
05/08/10 22:50
Joined: Oct 2008
Posts: 513
Carlos3DGS Offline OP
User
Carlos3DGS  Offline OP
User

Joined: Oct 2008
Posts: 513
I actually wanted a local entinty for that, not sure if I need a global for it.
The code has been cut and I only create one car to test it and debug. But the real code is more complicated and I dont only create one car, I create lots of them. The cars have to follow eachother down a street.
The entities themselves are not created there, they will be created in a "spawning control" function to populate my street with traffic.
The entity* pointer you refer to in the action is not used to create an entity, it is just a local pointer to the car in front of it to allow each car to follow the car in front correctly, so each car needs a pointer to the car in front. Think of it as a kind of single direction "linked list" with a pointer to "next" in the list. Only the difference is that it is not a linked list of structs created with malloc() and sizeof(), instead of structs they are entities created with ent_create() and the "next" pointer is controled in the action function with a local pointer. That way each car can individually see the car in front of it to see where it is.

Back to the subject of the while loop, it still seems to never return to the main function to make a call to load the parameters into the skills after the wait(1), it looks like it stays stuck in the while loop forever... Can anybody help me with this?


"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
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
O
Ottawa Offline
User
Ottawa  Offline
User
O

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 laugh

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 Offline OP
User
Carlos3DGS  Offline 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:
Quote:
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:
Quote:
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


"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
Re: Entity Action with parameters [Re: Carlos3DGS] #322737
05/09/10 00:40
05/09/10 00:40
Joined: Oct 2008
Posts: 513
Carlos3DGS Offline OP
User
Carlos3DGS  Offline 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

Quote:

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?


"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
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 Offline
Senior Member
Rich  Offline
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.

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
	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: Rich] #322758
05/09/10 10:20
05/09/10 10:20
Joined: Oct 2008
Posts: 513
Carlos3DGS Offline OP
User
Carlos3DGS  Offline OP
User

Joined: Oct 2008
Posts: 513
Thankyou, I was going crazy!
I reinstalled Gamestudio and after that the 2 function counter test script started to work fine (waits were working again) but my other script kept on getting stuck, I cant believe I missed that!
Thankyou very much! Sometimes your brain just freezes and refueses to notice the obvious and you need another view from someone else to find it. Thanks again!


"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
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 Offline
Senior Member
Rich  Offline
Senior Member

Joined: Jan 2002
Posts: 300
Usa
No problem, glad I could help laugh . 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 Offline OP
User
Carlos3DGS  Offline 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.

Code:
#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!


"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
Page 3 of 3 1 2 3

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1