Detect walls via lua script

  • MarkHuss
    13th May Member 0 Permalink

    How can I script a routine to check for walls?

    I dont think they appear in elements.default_PT...

     

    Or is there an indirect way?

     

    The use is this: I am making a particle type with procedurally determined velocities. I need the script to recognize when the particle is beside a wall.

     

    One thing I tried so far is to test sim.partID. If it is nil, act as if is was a wall. The problem is absence of particles is interpreted as a wall...

  • LBPHacker
    13th May Developer 0 Permalink

    Try tpt.get_wallmap(x, y). Note that the coordinates are cell coordinates. To convert from particle coordinates to cell coordinates, use math.floor(math.floor([x or y] + 0.5) / 4). I know it looks ugly but it's what it is :/ Here are the kinds of answers you can get from that function (it returns a number). I haven't found constants mapping them in the Lua API so you'll have to hardcode these. The division by 4 may seem arbitrary above but it's actually the CELL size (it's called that in the source), but I haven't found a constant in the Lua API for that either.

  • MarkHuss
    15th May Member 0 Permalink

    Immensely helpful, thank you.

     

    This function did not survive the new API?

  • jacob1
    15th May Developer 0 Permalink
    @MarkHuss (View Post)
    Are you referring to the fact that it's in the tpt. api, which is listed as legacy? It's not actually deprecated, there are no plans to remove functions in the legacy api*
    Simon created the new apis like sim. and ren. and added in some helpful functions, but much of the functionality doesn't overlap with tpt. We've also added a few things to tpt. since we started calling it the "legacy" api.

    *The event handlers in tpt. were both deprecated and removed in 94.0, then provided via a compatibility script. This is because there was no way to support the old api sanely.

    @LBPHacker (View Post)
    We should probably add sim.CELL as a constant
    Edited 2 times by jacob1. Last: 15th May
  • MarkHuss
    15th May Member 0 Permalink

    @jacob1 (View Post)

     And here I was trying to do everything with the new API, thinking it was intended as a replacement and that tpt. functions would eventually be deprecated and incompatible.

     

    Good to know it is not the case.

     

    Thank you!