*Solved* Help finding my coding error?

Posted By: MattyTheG

*Solved* Help finding my coding error? - 11/16/08 05:16

Hello everyone, I am working on a game and I wasn't having problems until I converted to .c files for the scripts instead of .wdl because I needed to use panels, but now when I go to call a function I get an error.

The error I get is "Crash in Main" when I press the space bar, which calls the gun_shoot() action. Any help is appreciated, below is the code for the main and gun_shoot().

Code:
action gun_shoot()
{
	ent_create("muzzleflash.mdl", vector(my.x + 130, my.y, my.z + 9), gun_flash);
	ent_create("bullet.mdl", vector(my.x + 135, my.y, my.z + 9), ball_fall);
	my.tilt += 15;
	wait (10);
	my.tilt -= 15;
	set(my,PASSABLE);
}

function main()
{	
	level_load ("Test.wmb");
	wait (2);
	while(1)
	{
		if (key_space == 1)
		{
			gun_shoot();
			wait(2);
		}
		else
		{
			wait(1);
		}
	}
}


Posted By: Uhrwerk

Re: Help finding my coding error? - 11/16/08 15:40

You are using the my pointer in the gun_shoot action. That is not allowed as gun_shoot is not attached to an entity. I guess what you wanted to do was:

Code:
action gun_shoot()
{
	ent_create("muzzleflash.mdl", vector(my.x + 130, my.y, my.z + 9), gun_flash);
	you = ent_create("bullet.mdl", vector(my.x + 135, my.y, my.z + 9), ball_fall);
	your.tilt += 15;
	wait (10);
	your.tilt -= 15;
	set(your,PASSABLE);
}

Posted By: MattyTheG

Re: Help finding my coding error? - 11/16/08 15:53

Thank you I will give that a shot. I was unaware that it was unattached to the entity since I set it as it's behavior in WDL, but none the less I shall try that code instead.

Is there any preference as to which is better, attaching the action to the entity, or using your instead of my?
Posted By: Uhrwerk

Re: Help finding my coding error? - 11/16/08 15:59

Usually attaching an action to an entity is the better way as it is mor intuitive and understandable by more people. But at least maybe just a matter of personal preferences...

If you attach gun_shoot to an entity in WED this will of course work. But you're calling gun_shoot from the main function and the main function is of course not attached to anything.
Posted By: MattyTheG

Re: Help finding my coding error? - 11/16/08 17:01

Thank you, I see what I was doing wrong now. I didn't realize that since it was already attached to an entity that I didn't have to call it or anything. I moved the while loop into the gun_shoot action and it works now. I have to fix it though since for some reason my physics doesn't work right now that I moved from .wdl scripts to .c , but that is for another time.
© 2024 lite-C Forums