Need help with C code

  • Videogamer555
    16th May 2012 Member 0 Permalink
    In an attempt to make BMTL flammable (and burn with hot plasma flame), whenever the temperature excedes 500kelvins, I used this code. I added it to the VERY beginning of the update function for BMTL, to make sure it gets executed every frame. The only code that comes before it is the variable declaration code that was already present in the update function (and as you can see I used the rx, ry, and r that was declared, for my function as well). I did EVERYTHING according to C code standard. But it DOES NOT WORK! Please help me. What am I doing wrong?
    if (parts[i].temp>500){
    rx=(rand()%3)-1+x;
    ry=(rand()%3)-1+y;
    if (pmap[ry][rx]&0xFF==PT_NONE){
    r=create_part(-1,rx,ry,PT_PLSM);
    parts[r].life=1000;
    parts[r].temp=3500;
    }
    }
  • vanquish349
    16th May 2012 Member 0 Permalink
    @Videogamer555 (View Post)
    use pastebin and paste the entire .c file
  • me4502
    16th May 2012 Member 0 Permalink
    @Videogamer555 (View Post)
    ...
    if (pmap[ry][rx] == null){


    if (parts[i].temp>500f + 273.15f){ ?
  • jacksonmj
    16th May 2012 Developer 1 Permalink
    Add some brackets around pmap[ry][rx]&0xFF. Operator precedence means == is evaluated before &, so your code currently checks (pmap[ry][rx]&(0xFF==PT_NONE)), which is always zero.

    It's also a good idea to check that creating a particle succeeded before setting its properties, so:
    if (parts[i].temp>500){
    rx=(rand()%3)-1+x;
    ry=(rand()%3)-1+y;
    if ((pmap[ry][rx]&0xFF)==PT_NONE){
    r=create_part(-1,rx,ry,PT_PLSM);
    if (r>=0)
    {
    parts[r].life=1000;
    parts[r].temp=3500;
    }
    }
    }
  • inventerfry
    5th Jul 2012 Member 2 Permalink
    This post has been removed by Xenocide: Garbage