Check for Solids/Powders in Lua?

  • NDR149
    13th Sep 2016 Member 0 Permalink

    I'm working on a custom element (liquid), it needs to be able to check exclusively for solids and powders as part of its update function. That way it doesn't try to react with itself or with gases. Can this be coded for in Lua?

  • jacob2
    13th Sep 2016 Member 0 Permalink
    Yes. You can use but.band(elem.property(<other element ID>, "Properties"), elem.TYPE_POWDER) ~= 0

    Maybe, I'm on a phone so can't test
    Edited 2 times by jacob2. Last: 13th Sep 2016
  • NDR149
    13th Sep 2016 Member 0 Permalink

    @jacob2 (View Post)

     Thank you. What to I replace "<other element id>" with?

  • jacob2
    13th Sep 2016 Member 0 Permalink
    @NDR149 (View Post)
    Whatever the type of the other element is. I don't know how your code is formatted, if you have a nearby particle id in 'r', then it would be sim.partProperty(r, sim.FIELD_TYPE)
  • NDR149
    14th Sep 2016 Member 0 Permalink

    @jacob2 (View Post)

     Wait a second. You were right to think you should test it first. I'd need to replace "elem.TYPE_POWDER" with some kind of or function, plus the bitwise operator might be too picky with neighboring elements. Unless I'm isreading the code, which is totally possible since I'm a potato. Can you show me how to actually use the code you provided?

  • TPT_PL
    14th Sep 2016 Member 0 Permalink
    @jacob2 (View Post)
    @NDR149 (View Post)
    Oh, I just found an error in jacob's code. It should be:
    bit.band(elem.property(, "Properties"), elem.TYPE_PART) ~= 0
    Notice that it isn't but.band, but bit.band and it also isn't elem.TYPE_POWDER, but elem.TYPE_PART
  • jacob2
    14th Sep 2016 Member 0 Permalink
    @NDR149 (View Post)
    If I remember, I'll write some example usage when I'm home

    @TPT_PL (View Post)
    Oops, phone keyboard.
  • NDR149
    14th Sep 2016 Member 0 Permalink

    @jacob2 (View Post)

     Nevermind, TPT_PL and I figured it out.