empty pointer?

Posted By: jonkuhl

empty pointer? - 02/16/08 05:12

I have a little tank that is suppose to turn and shoot the player when the player gets too close. Working so far.

However, I found that I use the little formula for pointing an object at another alot so I tried to make it its own function:

Code:

//turn to .wdl
//makes an object look at another object
//angleFrom is the vector the object to be looked at is
//angleTo is the euler angle that is turned.
function turnTo(angleFrom,angleTo)
{
var dirB[3];
vec_set(dirB,angleFrom);
vec_diff(dirB,dirB,my.x);
vec_to_angle(angleTo,dirB);
}




Problem is, when I put it in the game and run it, it spits out an empty pointer error.

Code:
 
action enemyTurret
{
//var dir[3];
while (!player){ wait(1); }
my.passable = on;
while(you)
{
my.health = you.health;
if(my.health < 0) { break;}
if(vec_dist(my.x,player.x) < 1000)
{
turnTo(player.x,my.pan);
//vec_set(dir,player.x);
//vec_diff(dir,dir,my.x);
//vec_to_angle(my.pan,dir);
}
else
{
my.pan = you.pan;
}
wait(1);
}
ent_remove(me);
}



The commented lines are what I originally had. I was hoping to give turnTo(); its own WDL file so I could use it in other projects.

The entity* player as of right now always exists and cannot yet be killed or removed from the game.

The problem I keep getting is "empty pointer: turnTo(player.x,my.pan);" What would be causing this and how can I be rid of it and still keep this function?
Posted By: G_Tos

Re: empty pointer? - 02/16/08 11:16

Hi jonkuhl,

perhaps you forgot to initialisize the pointer ENTITY* player; at the beginning of your script...
Posted By: kasimir

Re: empty pointer? - 02/16/08 11:20

i think its not the point:
"while (!player){ wait(1); } "
...that means the function does not start without the player?!
Posted By: MMike

Re: empty pointer? - 02/16/08 15:52

try while(player!=null){ do this...)
i think !player and player!=null do not do the same strict way
Posted By: ARAS

Re: empty pointer? - 02/16/08 19:54

Hi,

you have vectors no numbers in your "function turnTo".
Try this

function turnTo (&angleFrom,&angleTo)

and not

function turnTo (angleFrom,angleTo)
Posted By: jonkuhl

Re: empty pointer? - 02/17/08 00:23

Quote:

Hi,

you have vectors no numbers in your "function turnTo".
Try this

function turnTo (&angleFrom,&angleTo)

and not

function turnTo (angleFrom,angleTo)




Thank you. I seem to recall knowing this in the past, its been a while. But it now works as a separate function.
Posted By: jonkuhl

Re: empty pointer? - 02/17/08 00:24

Quote:

try while(player!=null){ do this...)
i think !player and player!=null do not do the same strict way




Can you clarify how !player and player != null is different?
Posted By: MMike

Re: empty pointer? - 02/17/08 20:48

I don't know but i guess they are not the same ...

!player can exist as a dummy but not an entity...
When you check for player!=null. you will check if it exists in the world :S

At least the !player sometimes for me does not work...



(&angleFrom,&angleTo) the & means it is a pointer.. instead of a plain var number
Posted By: jonkuhl

Re: empty pointer? - 02/18/08 03:52

Quote:

I don't know but i guess they are not the same ...

!player can exist as a dummy but not an entity...
When you check for player!=null. you will check if it exists in the world :S

At least the !player sometimes for me does not work...



(&angleFrom,&angleTo) the & means it is a pointer.. instead of a plain var number




So, if I understand you right, (!player) just checks if the pointer has not been defined and (player = null) checks if the pointer has been assigned to an action?
© 2024 lite-C Forums