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.

Last edited by heinekenbottle; 02/05/09 17:21.

I was once Anonymous_Alcoholic.

Code Breakpoint;