Coding TPT

  • greymatter
    27th Jun 2013 Member 1 Permalink
    Now I have started coding elements in TPT. And my very first element to use update has some problems.So I'll ask any doubt's that I have about coding TPT in this thread, starting with this element.

    I started out with a HTER(heater) element, like it's given in the wiki(Also, can someone finish updating that outdated tutorial?).
    I coded it, but only the first pixel of HTER placed heats up and it heats up to max temp instantly, rather than heating up gradually. Also, it's not heating up other elements, and only way it does that is by conducting heat(So it doesn't do anything with heatconduct=0.) . This might be a simple problem and i might have missed something obvious, But can someone help?

    I want the element to either constantly heat itself up, or heat up particles in a 4X4 grid.

    Here's the update part of the code:
    //#TPT-Directive ElementHeader Element_HTER static int update(UPDATE_FUNC_ARGS)
    int Element_HTER::update(UPDATE_FUNC_ARGS) {
    int r,rx,ry;
    for (rx=-2; rx<3; rx++)
    for (ry=-2; ry<3; ry++)
    if (BOUNDS_CHECK)
    {
    r=pmap[x+rx][y+ry];

    if(r&0xFF!=PT_HTER && parts[r>>8].temp + parts[r>>8].temp * 0.2f <= MAX_TEMP){

    parts[r>>8].temp += parts[r>>8].temp * 0.2f;

    }
    else {parts[r>>8].temp = MAX_TEMP;}
    }
    return 0;
    }
  • xetalim
    27th Jun 2013 Member 1 Permalink

    @greymatter (View Post)

     and only way it does that is by conducting heat(So it doesn't do anything with heatconduct=0.)

    what do you mean with that?

    do you want it to heat other elements up without conducting?

    or doesnt it conduct heat?

    if it doesnt conduct heat

    do heatconduct=256

  • jacob1
    27th Jun 2013 Developer 1 Permalink
    @xetalim (View Post)
    what? ...

    @greymatter (View Post)
    "if(r&0xFF!=PT_HTER && parts[r>>8].temp + parts[r>>8].temp * 0.2f <= MAX_TEMP){"

    you need parenthesis around the (r&0xFF), be sure to always to that everywhere you use it.
  • greymatter
    27th Jun 2013 Member 1 Permalink
    @xetalim (View Post)
    I want it to either heat itself up constantly, or heat the surrounding particles constantly without heating itself.
    @jacob1 (View Post)
    I did that, but still only the very first pixel of HTER placed heats up...
  • MiningMarsh
    27th Jun 2013 Member 1 Permalink

    @boxmein (View Post)

     > Proper indention makes the world go round.

     

    So why didn't you use tabs? (Cue religious coding war here.)

  • jacob1
    27th Jun 2013 Developer 1 Permalink
    I would actually say that indentation isn't right in more ways than just missing the tabs, but it's probably just my preference.

    if( (r&0xFF) != PT_HTER &&
    parts[r>>8].temp * 2.2f < MAX_TEMP) {

    why would you even make this two lines? That makes it more confusing to read. Also I don't really like the spacing with the if( (, it should be if ((

    Also I don't think comments should be put on the same line as the if, they should go before. I also don't like {'s on the same lines as fors or ifs either unless it just looks better and is small, and when it's just a one line for or if, you shouldn't really use { at all.

    //#TPT-Directive ElementHeader Element_HTER static int update(UPDATE_FUNC_ARGS)
    int Element_HTER::update(UPDATE_FUNC_ARGS)
    {
    int r, rx, ry;
    for (rx=-2; rx<3; rx++)
    for (ry=-2; ry<3; ry++)
    {
    r = pmap[y+ry][x+rx];
    // less expensive yet effective growth
    if(r && (r&0xFF) != PT_HTER && parts[r>>8].temp * 2.2f < MAX_TEMP)
    parts[r>>8].temp *= 2.2f;
    }
    return 0;
    }


    Edit: added cyberdragon's fix, didn't notice that. That is probably what is causing your problem
  • boxmein
    27th Jun 2013 Former Staff 1 Permalink
    @MiningMarsh (View Post)
    I have them replaced as spaces to make it look the same anywhere, as a personal preference.
    @jacob1 (View Post)
    personal preferences <3
  • cyberdragon
    27th Jun 2013 Member 1 Permalink

    I can see two imediate reasons why that won't operate

    1) you need this at the very bottom (outside the brakets)

     

    Element_HETR::~Element_HETR() {}

     

    2) you might want this after the pmap:

     

    if (!r)
    continue;

  • boxmein
    27th Jun 2013 Former Staff 1 Permalink
    @cyberdragon (View Post)
    and aside from everything else the graphics function stub and the property definition - we were talking exclusively about the update version...