Update Function Change Type

  • TheAwesomeMutant
    12th Feb 2017 Member 0 Permalink

    I want to change a particle from one type to another, whenever it's on screen.

  • Ligan
    12th Feb 2017 Member 0 Permalink

    Have you tried sim.partChangeType() ?

  • TheAwesomeMutant
    12th Feb 2017 Member 0 Permalink

    @Ligan (View Post)

    I tried that, how would I use it?

    Edited once by TheAwesomeMutant. Last: 12th Feb 2017
  • jacob1
    12th Feb 2017 Developer 0 Permalink
    sim.partChangeType(i, elem.DEFAULT_PT_DMND) would change the particle with ID "i" to diamond. You would need an update function to get "i".

    There is documentation in the wiki: https://powdertoy.co.uk/Wiki/W/Lua_API:Simulation.html#simulation.partChangeType

    By the way, you don't need to create a separate thread for every issue.
  • TheAwesomeMutant
    12th Feb 2017 Member 0 Permalink

    @jacob1 (View Post)

    Is there a way to have it change while paused?

  • jacob1
    12th Feb 2017 Developer 0 Permalink
    @TheAwesomeMutant (View Post)
    You would have to use a tick function for that, then do something like tpt.set_property("type", "dmnd", "stne"), this would change all stone to diamond
  • TheAwesomeMutant
    12th Feb 2017 Member 0 Permalink

    I can't use tpt.set_property because both elements have the same name.

  • jacob1
    12th Feb 2017 Developer 1 Permalink
    @TheAwesomeMutant (View Post)
    You're doing some *really* weird stuff ...

    The best you can do is this, but it will be a little laggier:

    if sim.elementCount(yourelement) > 0 then
        for i in sim.parts() do
            if sim.partProperty(sim.FIELD_TYPE, i) == yourelement then
                sim.partChangeType(i, elem.DEFAULT_PT_DMND)
            end
        end
    end

    Where "yourelement" is the ID of your element
    Edited 3 times by jacob1. Last: 12th Feb 2017
  • TheAwesomeMutant
    12th Feb 2017 Member 0 Permalink

    Wait, are you giving me a function or not?

    Edited once by TheAwesomeMutant. Last: 12th Feb 2017
  • jacob1
    12th Feb 2017 Developer 0 Permalink
    Hmm? Put that code in a tick function