particle problem

Posted By: Frederick_Lim

particle problem - 08/23/07 08:46

I port the laser script found in User Contribution to lite-c, but I always got E1515 in particle routine.
Code:
function laser_top()
{
VECTOR temp; vec_zero(temp);
my.pan=you.pan;
set(my,PASSABLE);
var shooting=0;
VECTOR mytarget;
var rotation_radius = 1500;
while (1)
{
my.pan=90;
my.tilt=-30;
shooting=0;
my.skill1 += 20 * time_step;
temp.x = my.x - rotation_radius * cos(my.skill1);
temp.y = my.y - rotation_radius * sin(my.skill1);
//temp.z = my.z - rotation_radius * sin(my.skill1);
c_trace(my.x, temp, IGNORE_ME|IGNORE_PASSABLE);
if (result != 0) // the player has hit something
{
if (you != NULL)
{
if((you != NULL)&&(you.skill11==2))
{
while((you != NULL)&&(you.healthpoints>0))
{
mytarget.x=you.x;
mytarget.y=you.y;
mytarget.z=you.z;
vec_set (temp.x,mytarget.x);
vec_sub (temp.x, my.x);
vec_to_angle (my.pan, temp);
if(shooting<=0)
{
snd_play(laser_wav,50,NULL);
vec_for_vertex(temp,my,38);
ent_create(lsrbolt_mdl,temp,laser_bolt);
shooting=random(20);
}
else
{
shooting-=1;
}
wait(1);
}
wait(10);
my.tilt=0;
}
}
}
wait (1);
}
}


function laser_bolt()
{
my.skill20=0;
set(my,TRANSLUCENT);
set(my,BRIGHT);
my.alpha=40;
my.red = 255;
my.green = 0;
my.blue = 0;
my.lightrange = 100;
VECTOR my_vertex;
VECTOR my_vertex2;
var hit_target=0;
my.pan=you.pan;
my.tilt=0;
my.emask |= (ENABLE_ENTITY);
my.event=im_gone;
while ((hit_target==0)&&( my.skill20<100))
{
vec_for_vertex(my_vertex,my,5);
vec_for_vertex(my_vertex2,my,6);
c_trace(my_vertex, my_vertex2, IGNORE_ME|IGNORE_PASSABLE);
if (result == 0)
{
ent_animate(my, "fire", my.skill20, ANM_CYCLE);
my.skill20 +=.2 * time_step;
}
else
{
if (you != NULL)
{
//if ((you != NULL)&&(you.skill11==2))
if (you.skill11==2)
{
you.healthpoints-=75;
vec_scale(normal,10);
effect(sparks,100,my_vertex,normal);
}
}
hit_target=1;
}
//wait(1);
}
wait(10);
ent_remove(me);
}

function sparks(PARTICLE *p)
{
VECTOR temp;
temp.x = random(20) - 10;
temp.y = random(20) - 10;
temp.z = random(20) - 10;
vec_add(p.vel_x, temp);
p.alpha = 70 + random(30);
p.red=255;
p.blue=0;
p.green=0;
p.size = 2;
my.flags |= (BRIGHT|MOVE);
p.lifespan = 20;
my.event = fade_sparks;
}

function fade_sparks(PARTICLE *p)
{
p.alpha -= 20*time_step;
if (p.alpha<=0)
{
p.lifespan=0;
}
}



If I take out the "PRACTICLE *p" in sparks function, and remove all p. attribute, no error occur.

Code:
function sparks()
{
VECTOR temp;
temp.x = random(20) - 10;
temp.y = random(20) - 10;
temp.z = random(20) - 10;
//vec_add(p.vel_x, temp);
//p.alpha = 70 + random(30);
//p.red=255;
//p.blue=0;
//p.green=0;
//p.size = 2;
/*my.flare = on;
my.bright = on;
my.move = on;*/
my.flags |= (BRIGHT|MOVE);
//p.lifespan = 20;
my.event = fade_sparks;
}



Why?
Posted By: jcl

Re: particle problem - 08/23/07 09:45

"p" and "my" are two different things. "p" is a particle and "my" is an entity pointer. So your code won't make sense and will probably crash. Both particles and entities have similar parameters, but setting entity parameters in a particle function is probably not what you intended.
Posted By: vlau

Re: particle problem - 08/23/07 09:47

Have you try to rearrange the order of those functions?

function fade_sparks(PARTICLE *p)
{
.....
.....
}

function sparks(PARTICLE *p)
{
.....
.....
}

function laser_bolt()
{
.....
}
function laser_top()
{
.....
}
Posted By: Frederick_Lim

Re: particle problem - 08/23/07 13:03

Yes, my original conversion is all "p."

Code:
function sparks(PARTICLE *p)
{
VECTOR temp;
temp.x = random(20) - 10;
temp.y = random(20) - 10;
temp.z = random(20) - 10;
vec_add(p.vel_x, temp);
p.alpha = 70 + random(30);
p.red=255;
p.blue=0;
p.green=0;
p.size = 2;
p.flags |= (BRIGHT|MOVE);
p.lifespan = 20;
p.event = fade_sparks;
}



But still cause E1515.

You may download the code and try lite-c laser

If you remark the "effect(sparks,100,my_vertex,nullvector);", the laser fire nicely.

If remove "PARTICLE *p" in sparks, no E1515 crash, like this
Code:
function sparks()
{
/*
VECTOR temp;
temp.x = random(20) - 10;
temp.y = random(20) - 10;
temp.z = random(20) - 10;
vec_add(p.vel_x, temp);
p.alpha = 70 + random(30);
p.red=255;
p.blue=0;
p.green=0;
p.size = 2;
p.flags |= (BRIGHT|MOVE);
p.lifespan = 20;*/
my.event = fade_sparks;
}



I know it does not make sense, but in case like this
Code:
function sparks(PARTICLE *p)
{
}


It still crash.
Posted By: Frederick_Lim

Re: particle problem - 08/28/07 02:30

Post deleted by Frederick_Lim

I found my problem because I haven't include the parameter type in function declaration:
Code:
function sparks(PARTICLE *);
function fade_sparks(PARTICLE *);


© 2023 lite-C Forums