player problem

Posted By: DAVIDMORETON

player problem - 09/25/09 11:16

Can anyone help please?
I need to 'call' the player in a function such that it will follow the platform it is standing on, simple example below:-

Function moveit
{
while (platform.x<200)
{
platform.x+=2*time;
player.x+=2*time;
wait(1);
}}

Result:- empty pointer in moveit: player.x+=2*time;

I can't seem to find a way to call the player in a function as it has already had it's action assigned, so I can't use 'entity* player'

Is there a way to do this?

yours hopefully, David

Top
Posted By: DJBMASTER

Re: player problem - 09/25/09 11:39

The empty pointer error means that "player" doesn't relate to anything. You need to make sure that you set the player pointer to a valid entity either by using it in an action like "player = me" or from the result of an ent_create call >> "player = ent_create(...)".
Posted By: DAVIDMORETON

Re: player problem - 09/25/09 15:28

Thanks BJDMaster for your reply,
I have added player=me; to the player01 script
and entity* player; to my running script ...........
The player still passes through the wall of the 'box' when it moves.
what am I doing wrong please?

sincerely, David
Posted By: ptrc1c

Re: player problem - 09/25/09 17:01

Go to Online Tutorial at the top left of the screen-workshop 11
You need to declare an ENTITY* ,say traveller

ENTITY* traveller;

then in your action somewhere

action traveller_with_pointer()
{
traveller = me;
etc...
}


Then use traveller.x in your function
Posted By: DAVIDMORETON

Re: player problem - 09/26/09 09:38

Thanks ptrc1c for your reply.

The problem is that the 'player' is already assigned in the 'actions' box (PIBiped01), this means that I can't call another 'action' to apply to it. (or of I can, I don't know how to do it)

I have tried everything I know to refere to the player, but nothing works. As the game is 3/4 finished (about three years work) I don't want to rewrite the whole script.

All I need is some means of refering to the player so that I can call it in a function.

If you can help, it would be great.
sincerely David
Posted By: EvilSOB

Re: player problem - 09/26/09 11:49

If you are definately using the pointer "player" in all your script then it shouldnt be a problem.

Its probably just a timing issue. That is, if the "moveit" function starts BEFORE player gets assigned, then the problem occurs...
Here are two suggestions for "moveit" to bypass the problem, my perferred one is the second one.

Code:
//commonly used process
function moveit
{ 
   while(player==NULL)    {  wait(1);  }
   while (platform.x<200)
   {
      platform.x+=2*time;
      player.x+=2*time;
      wait(1);
   }
} 


//my preferred process
function moveit
{ 
   while (platform.x<200)
   {
      platform.x+=2*time;
      if(player!=NULL)    {  player.x+=2*time;  }
      wait(1);
   }
}


Mind you, I assume you are aware that this code isnt checking to be sure the player is actually ON the platform?
If they step off it whilst it is moving, they'll continue to be moved by it....
Posted By: DAVIDMORETON

Re: player problem - 09/26/09 12:35

Hello evilSOB,
Many thanks for you reply. I have entered your first script exactly as stated, and got:-

"bad or missing parameter too complex"

I then tried your second (prefered) solution, the platform moved, but the player stayed put!!

Checked I had not made a mistake in the coding.

In the past (while trying to sort this out) I usually get "empty pointer" when refering to the 'player' Don't understand that either!
If you can help, I would be very pleased. NOTE I am working in c-script

sincerely, David
Posted By: EvilSOB

Re: player problem - 09/26/09 13:14

I myself dont use c-script, but did do some c-script->lite-c conversions in the past.
So Im helping in lite-c in my head, then converting to c-script as I type my posts.
So there may be some conversion errors there.

For instance, the 'bad or missing parameter' error MAY be due to both versions of 'moveit'
MAY need parameter brackets after thier names. eg "moveit()" instead of just "moveit".
In lite-c you need to, but it seems optional in c-script.
Put em on and try and see if the error goes away.

Anyway, regardless of the brackets issue, if the second one didnt work, there are several possible reasons.
1> The "moveit" function is not being run.
2> The player pointer is not pointing to your player entity.
3> The player is a physics entity, and so cannot be moved with simple co-ordinate adjustments.
4> There is another action somewhere limiting the players movements in the x direction.

I think options #1 or #3 are the most likely causes...

So unless you can supply some of the code then I cant help out more...
Say, the opening part of the players action? (up to the start of its while loop).
Or are you using the templates? In that case try replacing "player" with "plBiped01_entity" in the "moveit" function.
Otherwise Im out of ideas of how to help.
Posted By: DAVIDMORETON

Re: player problem - 09/26/09 13:53

Hi evilSOB,
Many thanks fo your reply and help, below is what I've done:-

room with box like lift in it, plus player with action PIBiped01 assigned.
player is in the box (open top) so that I can see if it moves with box.
code:-
(all required 'includes' in place)

entity* platform;

function moveit
{
while(platform.x<300)
{
platform.x+=2*time;
{
if(player!=NULL)
{
player.x+=2*time;
}
wait(1);
}}

action platform1
{
platform=my;
my.enable_click=on;
my.event=moveit;
}

Player still stays put, but the box moves nicely!!

Any thoughts? hopefully, David
Posted By: EvilSOB

Re: player problem - 09/26/09 14:33

Hmm, Ive never really used the templates at all, overly complex for my tastes.
I like to do things my way, and the template make that hard.
But hey, thats my problem, back to yours....

The "PIBiped01" templates dont actually use the "player" pointer, unless youve modded it in.
They use their own pointer which is called "plBiped01_entity" instead.

So try changing "moveit" to be this, and see how it goes...
Code:
function moveit()
{
   while(platform.x<300)
   { 
      platform.x+=2*time;
      if(plBiped01_entity!=NULL)    {   plBiped01_entity.x+=2*time;   }
      wait(1);
   }
}


Posted By: DAVIDMORETON

Re: player problem - 09/26/09 16:42

BRILLIANT evilSOB!!!!!!
Many,many thanks --IT WORKS, thank God for that, I was about to give up and redesign the level. (which uses a platform swinging around in an arc to transport the player on to the next section of problems)

I have spent hours going through the scripts to find something like this, had no idea they had a special '_entity' stuck on the end of the 'player' (plBiped01)

sorry to have bothered you so much, if I'm ever down your way, I'll drop in with a bottle! (or two)

YOU HAVE MADE MY DAY!!

thanks again, sincerely David (UK)
Posted By: EvilSOB

Re: player problem - 09/26/09 20:26

No problem dude...
© 2024 lite-C Forums