Tips for Coding Reactions?

  • godhydra
    22nd Dec 2018 Member 0 Permalink

    So far I've been able to create my own element and use it within the game, so now I want to try and attempt to learn how to make them react with other elements. I'm not too into coding, but I know a little bit. I just want to know a couple of things so I can understand what I'm looking at when looking at the code.

     

    function test(i, x, y, s, n)

    So I think x and y refer to the particle's position. I just want to know what i, s, and n are.

     

    Is there also an update function?

     

     

  • _Theo
    22nd Dec 2018 Member 0 Permalink

    Well I'm gonna explain (what I know atleast).

    I stands for the particle itself, it's ID or index, whatever you want to call it.

    S is the number of empty spaces around it.

    N is the neighboring particles, not their actual properties but just how many there are.

    And yes there's an update function.

  • godhydra
    22nd Dec 2018 Member 0 Permalink

    Thanks. Was finally able to make my first element with a reaction. :-)

     

    Edit: So after tooling around a bit, I've noticed that the elements that are involved in the reaction cause the FPS to drop after a lot of it is placed on screen, e.x If I made a reaction involving water with one of my elements then a lot of water would slow the fps down if the script was running. Is there a way to make the game run better?

    Edited once by godhydra. Last: 24th Dec 2018
  • _Theo
    24th Dec 2018 Member 0 Permalink

    I don't actually know, I have the same problem with the FPS hitting the floor as soon as I place lots of an element down, most notably sensor elements (those similar to TSNS, PSNS, LSNS). Probably because, for example, VSNS, a velocity sensor I made, has to do a whole ton of math to find out the total velocity of a particle, then generate spark in all directions, which is probably very hard for tpt to do.

  • godhydra
    12th Jan 2019 Member 0 Permalink

    I managed to fix it. I think it might have been because I was using the Update function instead of the element fuction. Works perfectly fine now.

  • jacob1
    12th Jan 2019 Developer 0 Permalink
    @godhydra (View Post)
    Do you mean the difference between elem.property("Update", ...) and tpt.element_func(...) ? Those are exactly the same thing and you should use the first one since that api is newer.

    Lua elements are just inherently slow. There aren't too many things we can do to fix it. The transition between C++ to Lua (updating element) and Lua to C++ (calling a tpt-related Lua function) are just too slow. Maybe try reducing Lua function calls.