empty pointer in door left and door right

Posted By: xbox

empty pointer in door left and door right - 05/06/11 03:57

I don't understand the error at all, I'm not a complete noob to this but I don't see a reason for error. Can anyone please help?
Code:
#define init_xpos skill1

action door_left()
{
	while(!player)
	{
		wait (1);
	}
	my.init_xpos = my.x;
	while(1)
	{
		while(vec_dist(player.x, my.x > 30))
		{
			wait(1);
		}
		while(my.x > (my.init_xpos - 40))
		{
			my.x -= 3 * time_step;
			wait(1);
		}
		while (vec_dist(player.x, my.x) < 100)
		{
			wait(1);
		}
		while (my.x < my.init_xpos)
		{
			my.x += 3 * time_step;
			wait(1);
		}
		my.x = my.init_xpos;
		wait(1);
	}
}

action door_right()
{
	while(!player)
	{
		wait(1);
	}
	my.init_xpos = my.x;
	while(1)
	{
		while(vec_dist(player.x, my.x > 30))
		{
			wait (1);
		}
		while(my.x < (my.init_xpos + 40))
		{
			my.x += 3 * time_step;
			wait(1);
		}
		while (vec_dist(player.x, my.x) < 100)
		{
			wait(1);
		}
		while (my.x > my.init_xpos)
		{
			my.x -= 3 * time_step;
			wait(1);
		}
		my.x = my.init_xpos;
		wait(1);
	}
}


Posted By: Schubido

Re: empty pointer in door left and door right - 05/06/11 07:37

IMHO code looks fine. The only thing I could imagine is that "player" becomes invalid at a certain time.
So a "if (!player) break;" after each "wait(1)" might help.

Beside that I would recommend to have only one while loop and track a state instead of having cascading whiles. But thats more a design philosophy and should not be the cause of the error.
Posted By: Myrkling

Re: empty pointer in door left and door right - 05/06/11 08:45

vec_dist(player.x, my.x > 30)

should be

vec_dist(player.x, my.x) > 30
Posted By: Schubido

Re: empty pointer in door left and door right - 05/06/11 10:20

Wow - great syntax parsing - didn't see that ;-)
Posted By: xbox

Re: empty pointer in door left and door right - 05/06/11 13:32

Wow, something so easily overlooked. Thanks a bunch man. grin
© 2024 lite-C Forums