|
*Solved* Help finding my coding error?
#236728
11/16/08 05:16
11/16/08 05:16
|
Joined: Jul 2007
Posts: 48
MattyTheG
OP
Newbie
|
OP
Newbie
Joined: Jul 2007
Posts: 48
|
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().
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);
}
}
}
Last edited by MattyTheG; 11/16/08 17:02.
|
|
|
Re: Help finding my coding error?
[Re: MattyTheG]
#236779
11/16/08 15:40
11/16/08 15:40
|
Joined: Jan 2002
Posts: 4,225 Germany / Essen
Uhrwerk
Expert
|
Expert
Joined: Jan 2002
Posts: 4,225
Germany / Essen
|
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: 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);
}
Always learn from history, to be sure you make the same mistakes again...
|
|
|
Re: Help finding my coding error?
[Re: MattyTheG]
#236784
11/16/08 15:59
11/16/08 15:59
|
Joined: Jan 2002
Posts: 4,225 Germany / Essen
Uhrwerk
Expert
|
Expert
Joined: Jan 2002
Posts: 4,225
Germany / Essen
|
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.
Always learn from history, to be sure you make the same mistakes again...
|
|
|
Moderated by mk_1, Perro, rayp, Realspawn, Rei_Ayanami, rvL_eXile, Spirit, Superku, Tobias, TSG_Torsten, VeT
|