Make elements mix with Lua modding?

  • megamageiii
    1st May 2014 Member 0 Permalink

    I'm sorry if this is a simple question, but I am new to Lua modding, and I am unsure how to make 2 elements mix. For example, if I wanted DUST and WATR to make CNCT, what line(s) would I need to put in? I could probably do something like 'if tpt.getproperty('type', x + 1, y)' for each of the sides of the particle, but I think there might be an easier way. Is there? And if there is, what is it?

  • boxmein
    1st May 2014 Former Staff 0 Permalink
    Something like this might work:
    function newdustupdate (index, x, y, surround_space, no_type)
    -- find WATR particles:
    -- go over the moore neighborhood of the particle
    for part in sim.neighbors(x, y, 1, 1)
    -- if a particle in the moore neighborhood has the type WATR (expressed as an integer,
    -- so tpt.element is used to convert the string "WATR" too into an integer)
    if sim.partProperty(part, 'type') == tpt.element('WATR') then
    -- create a concrete particle in dust's place
    -- edit2: jehkab one wuz heer 2, also fancy field_* constants!
    sim.partCreate(part, sim.partProperty(part, sim.FIELD_X), sim.partProperty(part, sim.FIELD_Y), elem.DEFAULT_PT_CNCT)

    sim.partKill(i)
    return 1
    end
    end
    end
    end
    -- element_func is cooler than partProperty("Update",...) maybe
    tpt.element_func(newdustupdate, tpt.element('DUST'))
    Edited 6 times by boxmein. Last: 2nd May 2014
  • jacob1
    1st May 2014 Developer 0 Permalink
    @boxmein (View Post)
    returning 1 doesn't actually do anything besides skip the movement code. You still have to kill part i.

    I would change that middle part to:
    sim.partCreate(part, sim.partProperty(part, sim.FIELD_X), sim.partProperty(part, sim.FIELD_Y), elem.DEFAULT_PT_CNCT)
    sim.partKill(i)
    return 1
  • megamageiii
    2nd May 2014 Member 0 Permalink

    It says 'do expected near if' on the line with if, so I put a 'do' on the 'for' before it, and it fixed that, and then it said ''<eof>' expected near end' on the last end. I'm new to Lua, so I'm not sure what the issue is.

  • jacob1
    2nd May 2014 Developer 0 Permalink
    it looks like he accidentally put an extra "end", try removing one of them.
  • megamageiii
    2nd May 2014 Member 0 Permalink

    I did that, and now DUST just destroys WATR and makes nothing.

  • jacob1
    2nd May 2014 Developer 0 Permalink
    did you replace the inner if statement content with the thing from my post? It should work and actually make the reaction happen

    Edit: maybe it still doesn't work ... i'll look at it later when I have more time
    Edited once by jacob1. Last: 2nd May 2014
  • megamageiii
    2nd May 2014 Member 0 Permalink

    Actually, I forgot to put your edit in. This time it worked in making the CNCT, but the DUST wasn't destroyed.

     

    EDIT:

    I changed sim.partKill(i)to

    sim.partKill(index)

    and it worked! Thank you!

    Edited once by megamageiii. Last: 2nd May 2014