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 2 of 3 1 2 3
Re: Entity Action with parameters [Re: Widi] #322388
05/06/10 16:15
05/06/10 16:15
Joined: May 2007
Posts: 2,043
Germany
Lukas Offline

Programmer
Lukas  Offline

Programmer

Joined: May 2007
Posts: 2,043
Germany
I already gave you an example of a cast:
(ENTITY*)my.skill1

A cast works always like this:
(type)object

So, in this case, my.skill1 gets converted from its old type (var) to an ENTITY* pointer.


What Widi says its true, but this also affects any other pointer; but this is only the case if you use game_save/load.

Re: Entity Action with parameters [Re: Lukas] #322413
05/06/10 19:09
05/06/10 19:09
Joined: Oct 2008
Posts: 513
Carlos3DGS Offline OP
User
Carlos3DGS  Offline 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:
Quote:
if(PreviousCar!=NULL)//If there exists a previous car or I am the first


PreviousCar is an entity declared like this:
Quote:
ENTITY* PreviousCar;


And before that function is called it is initialized as:
Quote:
PreviousCar=NULL;



The crash gives me Error E1514 so I think it must be related to that
Quote:
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?


"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] #322418
05/06/10 20:03
05/06/10 20:03
Joined: Dec 2006
Posts: 1,086
Queensland - Australia
Nidhogg Offline
Serious User
Nidhogg  Offline
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 Offline OP
User
Carlos3DGS  Offline OP
User

Joined: Oct 2008
Posts: 513
More or less...
I added it but it dosent point to me
Quote:
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


"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] #322446
05/06/10 23:45
05/06/10 23:45
Joined: Nov 2007
Posts: 1,143
United Kingdom
DJBMASTER Offline
Serious User
DJBMASTER  Offline
Serious User

Joined: Nov 2007
Posts: 1,143
United Kingdom
if(PreviousCar != NULL) or if(PreviousCar) is the usual way to check if a pointer is valid.

I'm not sure why it wouldn't work correctly?

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
M
MrGuest Offline
Serious User
MrGuest  Offline
Serious User
M

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
Code:
ENTITY* PrevCar;
PrevCar = NULL;

you can just use
Code:
ENTITY* PrevCar = NULL;



Re: Entity Action with parameters [Re: MrGuest] #322613
05/08/10 12:53
05/08/10 12:53
Joined: Oct 2008
Posts: 513
Carlos3DGS Offline OP
User
Carlos3DGS  Offline 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

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
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
M
MrGuest Offline
Serious User
MrGuest  Offline
Serious User
M

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
Code:
main();


in main you have
Code:
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 Offline OP
User
Carlos3DGS  Offline 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?

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("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?


"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] #322651
05/08/10 17:06
05/08/10 17: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'm looking at your code.
Here's what I found so far.

Quote:

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 laugh

Ver 7.86.2 Pro and Lite-C
Page 2 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