Gamestudio Links
Zorro Links
Newest Posts
Data from CSV not parsed correctly
by dr_panther. 05/06/24 18:50
Help with plotting multiple ZigZag
by degenerate_762. 04/30/24 23:23
M1 Oversampling
by 11honza11. 04/30/24 08:16
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
3 registered members (AndrewAMD, TedMar, dr_panther), 1,049 guests, and 0 spiders.
Key: Admin, Global Mod, Mod
Newest Members
firatv, wandaluciaia, Mega_Rod, EternallyCurious, howardR
19050 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 2 of 2 1 2
Re: Empty Pointer [Re: V_Sola] #250042
02/05/09 17:20
02/05/09 17:20
Joined: Oct 2008
Posts: 218
Nashua NH
heinekenbottle Offline
Member
heinekenbottle  Offline
Member

Joined: Oct 2008
Posts: 218
Nashua NH
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;
Re: Empty Pointer [Re: V_Sola] #250047
02/05/09 18:02
02/05/09 18:02
Joined: Apr 2008
Posts: 437
dracula Offline
Senior Member
dracula  Offline
Senior Member

Joined: Apr 2008
Posts: 437
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

Re: Empty Pointer [Re: dracula] #250059
02/05/09 19:31
02/05/09 19:31
Joined: Oct 2008
Posts: 218
Nashua NH
heinekenbottle Offline
Member
heinekenbottle  Offline
Member

Joined: Oct 2008
Posts: 218
Nashua NH
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.

Last edited by heinekenbottle; 02/05/09 19:33.

I was once Anonymous_Alcoholic.

Code Breakpoint;
Re: Empty Pointer [Re: heinekenbottle] #250257
02/06/09 22:33
02/06/09 22:33
Joined: Nov 2007
Posts: 13
Germany / Munich
V
V_Sola Offline OP
Newbie
V_Sola  Offline OP
Newbie
V

Joined: Nov 2007
Posts: 13
Germany / Munich
thanks guys!

the problem is solved.

Re: Empty Pointer [Re: V_Sola] #250977
02/11/09 01:43
02/11/09 01:43
Joined: Aug 2006
Posts: 70
NJ
S
SirCamaris Offline
Junior Member
SirCamaris  Offline
Junior Member
S

Joined: Aug 2006
Posts: 70
NJ
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!

Page 2 of 2 1 2

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