Creating elements

  • Shadow79473
    17th Nov 2012 Member 0 Permalink

    Is there any way I can create a copy of an element like say fire then rename the copy of the element and change the propeties?

  • cracker64
    17th Nov 2012 Developer 0 Permalink

    Read the wiki page

    https://powdertoy.co.uk/Wiki/W/Lua_API:Elements.html

    There is a specific example of creating an element with copied properties.

  • Shadow79473
    17th Nov 2012 Member 0 Permalink

    Okay thanks but i can't figure out how to set it's default life...

  • jacob1
    17th Nov 2012 Developer 0 Permalink
    @Shadow79473 (View Post)
    there is no way right now, but it's something I plan to add soon, so that each element has an onCreate function or something. For now, you have to do weird things like checking if it doesn't have a tmp, then setting the life to an initial value and tmp to one so it doesn't happen again.
  • Shadow79473
    17th Nov 2012 Member 0 Permalink

    @jacob1 (View Post)

     Do you know of any way i can have my script on the particle being created check to see if its life is set?

  • jacob1
    18th Nov 2012 Developer 0 Permalink
    if tpt.get_property("tmp",i) == 0 then
    tpt.set_property("life",6400,i);
    tpt.set_property("tmp",1,i);
    end

    This will set it's life to 6400 on creation. Sort of taken from my virus element that I converted into a lua script (but never released because of lag)
  • Shadow79473
    18th Nov 2012 Member 0 Permalink

    @jacob1 (View Post)

    Cracker64's Lua script launcher's console output is telling me that "Partical Doesn't Exist"

  • cracker64
    18th Nov 2012 Developer 0 Permalink

    @Shadow79473 (View Post)

    that code snippet would go in the element update function for that element, not by itself.

    local updatefunc = function(i,x,y,surround,nt)
    if tpt.get_property("tmp",i) == 0 then
    tpt.set_property("life",6400,i);
    tpt.set_property("tmp",1,i);
    end
    end
    tpt.element_func( updatefunc , elements.PT_YOUR_ELEMENT)

  • Shadow79473
    18th Nov 2012 Member 0 Permalink

    Can i get some more help i'm very new to Lua, here is my code.

    local myNewElement = elements.allocate("MOD", "SUN")
    elements.element(elements.MOD_PT_SUN, elements.element(elements.DEFAULT_PT_EMBR))
    elements.property(elements.MOD_PT_SUN, "Name", "SUN")
    elements.property(elements.MOD_PT_SUN, "Description", "Sun")
    elements.property(elements.MOD_PT_SUN, "Gravity", "0")
    elements.property(elements.MOD_PT_SUN, "Falldown", "0")
    elements.property(elements.MOD_PT_SUN, "Temperature", "9000")
    elements.property(elements.MOD_PT_SUN, "Colour", 0xFFFE9E19)

     I need to get my Element to have life when created

     

    EDIT: I solved the life problem, now i need to have a sparkle effect like EMBR

  • timpfeifer
    28th Dec 2012 Member 0 Permalink

    ask boxmein