Ctype shenanigans

  • Ketemin
    5th Jun 2019 Member 0 Permalink

    So, I dont even know if this would be possible, but, I would like to know how to make a function that would allow powders to be disolved in water (Water ctype changing for saltwater not saltwater being its own thing).

     

    The same could work for metals and acid, hopefully. Acid disolves Metal, Acid with metal ctype, when heated metal comes out of solution as metal powder, BMTL and BRMT.

     

    If anyone could help, it would be much appreciated. This has been mind bogglingly difficult for me to do so far.

    EDIT: Il'd also like the function for when BRMT melts the solid formed when cooled is BMTL, if anyone has that, that would be cool too.

    EDIT 2: I found out how to do the BRMT melting and cooling into BMTL.

    Edited 2 times by Ketemin. Last: 5th Jun 2019
  • LBPHacker
    5th Jun 2019 Developer 0 Permalink

    Extending the behaviour of built-in elements is generally difficult through Lua, and changing them completely is mostly impossible. You could get WATR to dissolve powders which it doesn't already dissolve, but the reactions with the ones it does (SALT is the only one coming to mind right now) would probably be impossible to rig.

     

    ACID dissolves stuff based on its Hardness property and loses some of its potency every time it dissolves a particle. This means that it's not always obvious what's "dissolved" in an ACID particle, so I'm not even sure how to approach this. Regardless, the same things apply as above.

    Edited once by LBPHacker. Last: 5th Jun 2019
  • MarkHuss
    9th Jun 2019 Member 0 Permalink

    I'm very new to Lua, so I may be off, but try the element I coded as a proof of concept.

     

    Make sure the MTWT element is "loaded", and then simply use standard WATR element to test diluting in it.

    You can see different elements mixed in water are diluted, and water gets a corresponding ctype, with a different color to better see it. You could code anything after this. Is this what you wanted?

     

     

     

     

     

     

    elem.allocate("MARKHUSS", "MTWT")

    elem.element(elem.MARKHUSS_PT_MTWT, elem.element(elem.DEFAULT_PT_DMND))

    elem.property(elem.MARKHUSS_PT_MTWT, "Name", "MTWT")

    elem.property(elem.MARKHUSS_PT_MTWT, "Description", "markHuss test water for ctype shenanigans")

    elem.property(elem.MARKHUSS_PT_MTWT, "Colour", 0x2030d0)

    elem.property(elem.MARKHUSS_PT_MTWT, "MenuVisible", 0)

    elem.property(elem.MARKHUSS_PT_MTWT, "MenuSection", SC_SPECIAL)

    elem.property(elem.MARKHUSS_PT_MTWT, "Advection", 0.6)

    elem.property(elem.MARKHUSS_PT_MTWT, "AirDrag", 0.01)

    elem.property(elem.MARKHUSS_PT_MTWT, "AirLoss", 0.98)

    elem.property(elem.MARKHUSS_PT_MTWT, "Loss", 0.95)

    elem.property(elem.MARKHUSS_PT_MTWT, "Collision", 0)

    elem.property(elem.MARKHUSS_PT_MTWT, "Gravity", 0.1)

    elem.property(elem.MARKHUSS_PT_MTWT, "Diffusion", 0)

    elem.property(elem.MARKHUSS_PT_MTWT, "HotAir", 0)

    elem.property(elem.MARKHUSS_PT_MTWT, "Explosive", 0)

    elem.property(elem.MARKHUSS_PT_MTWT, "Flammable", 0)

    elem.property(elem.MARKHUSS_PT_MTWT, "Hardness", 20)

    elem.property(elem.MARKHUSS_PT_MTWT, "Meltable", 0)

    elem.property(elem.MARKHUSS_PT_MTWT, "Weight", 30)

    elem.property(elem.MARKHUSS_PT_MTWT, "HeatConduct", 29)

    elem.property(elem.MARKHUSS_PT_MTWT, "Temperature", 293.15)

    elem.property(elem.MARKHUSS_PT_MTWT, "Falldown", 2)

    elem.property(elem.MARKHUSS_PT_MTWT, "State", elem.ST_LIQUID)

    elem.property(elem.MARKHUSS_PT_MTWT, "Properties", elem.TYPE_LIQUID)

    elem.property(elem.MARKHUSS_PT_MTWT, "LowPressure", IPL)

    elem.property(elem.MARKHUSS_PT_MTWT, "LowPressureTransition", NT)

    elem.property(elem.MARKHUSS_PT_MTWT, "HighPressure", IPH)

    elem.property(elem.MARKHUSS_PT_MTWT, "HighPressureTransition", NT)

    elem.property(elem.MARKHUSS_PT_MTWT, "LowTemperature", ITL)

    elem.property(elem.MARKHUSS_PT_MTWT, "LowTemperatureTransition", NT)

    elem.property(elem.MARKHUSS_PT_MTWT, "HighTemperature", ITH)

    elem.property(elem.MARKHUSS_PT_MTWT, "HighTemperatureTransition", NT)

    function MTWT_Update(i, x, y, ss, nt)

    close=nt-ss

    if close >= 4 then

    b=sim.partID(x, y+1)

    if b==nil then else

    s_ct = sim.partProperty(b, sim.FIELD_TYPE)

    if s_ct~= elements.DEFAULT_PT_WATR then

    sim.partKill(x, y+1)

    repl = sim.partCreate(-3, x, y+1, elements.DEFAULT_PT_WATR)

    sim.partProperty(repl, sim.FIELD_CTYPE, s_ct)

    colo= sim.decoColour(s_ct*2, (close*45), (s_ct*2 + close *20))

    sim.partProperty(repl, sim.FIELD_DCOLOUR, sim.decoColour())

    end

    end

    --print("close", close, "s_ct", s_ct, "repl", repl, "color", colo)

    end

    end

    elements.property(elem.DEFAULT_PT_WATR, "Update", MTWT_Update, 1)

    function MTWT_Graphics(i, colr, colg, colb)

    return 1, 0x0000001, 255, colr, colg, colb, 0, 0, 0, 0

    end

    elements.property(elem.MARKHUSS_PT_MTWT, "Graphics", MTWT_Graphics)

    Edited once by MarkHuss. Last: 9th Jun 2019
  • LBPHacker
    9th Jun 2019 Developer 0 Permalink

    @MarkHuss (View Post)

     

    You talk about (non-existent) syntactic conventions in the other thread (and ignore advice), but you don't use locals (which is actually a convention). Nice :P

     

    Here, have some correct Lua code. You should use pastebin next time too. Kudos for knowing about the second argument of the Update property.

     

    Edit: Wow, I just noticed that the impossible pressure and temperature constants are not available in the Lua API. Will fix that later.

    Edited 3 times by LBPHacker. Last: 9th Jun 2019
  • MarkHuss
    9th Jun 2019 Member 0 Permalink

    @LBPHacker (View Post)

     

     

    My goal here is OP request. My only concern is functioning code, I dont care about conventions as long as the code works.

     

    And your "corrected" code does not work...

     

    What is your intent here?

  • LBPHacker
    9th Jun 2019 Developer 0 Permalink

    My intent was to fix your code so it doesn't look like oatmeal, which I've achieved.

  • MarkHuss
    10th Jun 2019 Member 0 Permalink

    @Ketemin (View Post)

     keep me updated. curious where you are going with this

  • Ketemin
    26th Jun 2019 Member 0 Permalink

    @MarkHuss (View Post)

     Im making a realistic chemistry lua mod. So far I have a handful of metals and non-metals and basic reactions between them.
    My goal is to do things I havent seen in other mods, for example metal alloying in a realistic way.
    What I am currently working on is an aqueous solution for every compound, metal and what ever else dissolves. Ive also added alkali metals and their reactions. This is a massive pain in the ass to make but im slowly getting there.

  • Alexwall
    27th Jun 2019 Member 0 Permalink

    LBPHacker:

    @MarkHuss (View Post)

     

    You talk about (non-existent) syntactic conventions in the other thread (and ignore advice), but you don't use locals (which is actually a convention). Nice :P

     

    Here, have some correct Lua code. You should use pastebin next time too. Kudos for knowing about the second argument of the Update property.

     

    Edit: Wow, I just noticed that the impossible pressure and temperature constants are not available in the Lua API. Will fix that later.

     

    LBPHacker:

    My intent was to fix your code so it doesn't look like oatmeal, which I've achieved.

     

    Obviously my way is the best way https://pastebin.com/ai3w0d9M

  • Ketemin
    27th Jun 2019 Member 0 Permalink

    Well, none of these are really the best way. I have since found a workabout for what I am looking for.