Empty Pointer

Posted By: V_Sola

Empty Pointer - 02/01/09 14:27

Hi, i wrote a code in which i used a Pointer that should tell my player-model to move on w

ENTITY* robot;


function move_ahead()
{
robot.x += 5;
}

function main()
{
video_switch (8,32,1);
level_load ("Drohne_Level.wmb");
on_w = move_ahead;
}


action Drohne()
{
robot = me;
}


, but after i had started the programm
evertime i pressed the engine only told me theres an empty Pointer.

Does anyone know what's my mistake?

Thanks in advance, v_sola.
Posted By: Cowabanga

Re: Empty Pointer - 02/01/09 14:31

Try this instead! smile

Code:
function move_ahead()
{
	robot.x += 5;
}

function main()
{
	video_switch (8,32,1);
	level_load ("Drohne_Level.wmb");
	on_w = move_ahead;
}

action Drohne()
{
	robot = my;
}

Posted By: V_Sola

Re: Empty Pointer - 02/01/09 14:44

I tried this but there's still the problem. Did i make anything wrong?
Posted By: Cowabanga

Re: Empty Pointer - 02/01/09 14:53

Nothing is wrong in your code. What's your version?
Posted By: Xarthor

Re: Empty Pointer - 02/01/09 14:59

Do you have an entity that has the action "Drohne" attached to it?
Posted By: V_Sola

Re: Empty Pointer - 02/01/09 14:59

Gamestudio Commercial 7.07 ; SED version 7.06.1 . Did you mean that?
Posted By: Cowabanga

Re: Empty Pointer - 02/01/09 15:02

Update to A7.66, Then try this:

Code:
#include <acknex.h>

function move_ahead()
{
	robot.x += 5;
}

function main()
{
	video_switch (8,32,1);
	level_load ("Drohne_Level.wmb");
	on_w = move_ahead;
}

action Drohne()
{
	robot = my;
}

Posted By: croman

Re: Empty Pointer - 02/01/09 15:17

error is "on_w = move_ahead;" part of the code. try with this instead "on_w" part:

while(1)
{
if(key_w) move_ahead;
wait(1);
}
Posted By: Spirit

Re: Empty Pointer - 02/01/09 15:30

I think Xarthor nailed it, when you get empty pointer, your action "Drohne" does not run so the pointer is not set, have you entered the Drohne action in WED for your robot model?
Posted By: V_Sola

Re: Empty Pointer - 02/05/09 17:04

Sry but the problem still exists.

Does someone have a code which can move any model ?

thanks in advance, v_sola.
Posted By: heinekenbottle

Re: Empty Pointer - 02/05/09 17:20

ENTITY* robot;


function move_ahead()
{
robot.x += 5;
}

function main()
{
video_switch (8,32,1);
level_load ("Drohne_Level.wmb");
while(!robot) wait(1); //wait for the robot to load
on_w = move_ahead;
}


action Drohne()
{
robot = me;
}

In red, I added a while loop. This will halt the function until the model, which the robot pointer points to, loads into the game (about a half a second or less, on a decent computer, probably only a frame). It is a very short amount of time, but chances are the engine will read "on_w = move_ahead;" and call function move_ahead() before the robot even loads.

However, this entire problem can be avoided by combining move_ahead() with Drohne():

Code:
action Drohne()
{
  robot = my;
  while(1)
  {
     my.x += 5 * key_w;
     wait(1);
  }
}


This eliminates the need for a function and also reduces the use of pointers (in this simple code it actually won't be necessary to have a pointer at all). Since pointers can be very tricky some times, I prefer to avoid using them when possible.
Posted By: dracula

Re: Empty Pointer - 02/05/09 18:02

Originally Posted By: V_Sola
while(!robot) wait(1); //wait for the robot to load


This is useful to know, I just write wait(1); but I shall use the above

Thanks
Posted By: heinekenbottle

Re: Empty Pointer - 02/05/09 19:31

If you do, just remember that everything after that while loop won't happen until the pointer is valid.

function main might actually be a bad spot for such a loop, another alternative would be to just use "wait()"

or if you want to be absolutely sure, another way would be

Code:
function move_ahead()
{
  if(!robot) return;

  robot.x += 5;
}


Which terminates the function if robot is invalid, ergo no missing pointer.
Posted By: V_Sola

Re: Empty Pointer - 02/06/09 22:33

thanks guys!

the problem is solved.
Posted By: SirCamaris

Re: Empty Pointer - 02/11/09 01:43

There are some differences between c-script and lite-c file types. First I would try saving them in both file types to see if one works. If not, combine some of the previous advice given by other members in this forum with this lite-c code:
Code:
#include <acknex.h>

function move_ahead()
{
	robot.x += 5;
}

function main()
{
	video_switch (8,32,1);
	level_load ("Drohne_Level.wmb");
         wait (2);      //let the level load.
	//on_w = move_ahead;  ignore this command for now
}

action Drohne()
{   robot = my;
    while(1)
    {    if (key_w == 1) //key_w is pressed
         {    while (key_w == 1) //while key_w is being held
              {wait(1);} //wait a frame
               move_ahead();  //then call move_ahead function using
                              //parentheses or syntax error will occur.
         }
     wait(1);
    }
}

Again, make sure the Drohne action is attached to the model you want to move in WED. Compile the level first, then run it and press 'w'.
Hope this helps!
© 2024 lite-C Forums