Help...(Please noone laugh at me)

  • batman333
    24th Sep 2014 Member 0 Permalink

    I'm new to lua, how would I make two elements colide into each other to make a different one (e.g. Water+Clst=paste)

  • QuentinADay
    24th Sep 2014 Member 1 Permalink

    this should work:  

     

    function something(i,x,y,s,n)
    type = tpt.get_property("type", x + math.random(-1,1), y + math.random(-1,1))
    if type == tpt.el.watr.id then
    tpt.parts[i].type = tpt.el.pste.id
    end
    end
    tpt.element_func(something,tpt.el.clst.id)

     

     

    line 3 is the first element

    line 7 is the second element

    and line 4 is the resulting element

    Edited 3 times by QuentinADay. Last: 24th Sep 2014
  • jacob1
    24th Sep 2014 Developer 3 Permalink
    @QuentinADay (View Post)
    that's really close, but I suggest never using tpt.parts in a real script. Also directly setting type is bad, you should use sim.partChangeType(i, tpt.el.pste.id) instead.


    @batman333 (View Post)
    So uh, what QuentinADay said.
  • QuentinADay
    24th Sep 2014 Member 0 Permalink

    also if you do it the way i just did you might want to do this: 

     


    function something(i,x,y,s,n)
    type = tpt.get_property("type", x + math.random(-1,1), y + math.random(-1,1))
    if type == tpt.el.clst.id then
    tpt.parts[i].type = tpt.el.pste.id
    end
    end
    tpt.element_func(something,tpt.el.watr.id)

     

    function something(i,x,y,s,n)
    type = tpt.get_property("type", x + math.random(-1,1), y + math.random(-1,1))
    if type == tpt.el.watr.id then
    tpt.parts[i].type = tpt.el.pste.id
    end
    end
    tpt.element_func(something,tpt.el.clst.id)

     

    it makes it so not just one turns to pste but both turn to pste. 

  • jward212
    24th Sep 2014 Member 0 Permalink

    also you can name the function, I just use the element its for due to me being bad at making names :P

     

    function pasteReaction(i,x,y,s,n)
    type = tpt.get_property("type", x + math.random(-1,1), y + math.random(-1,1))
    if type == tpt.el.watr.id then
    tpt.parts[i].type = tpt.el.pste.id
    end
    end
    tpt.element_func(pasteReaction,tpt.el.clst.id)

     

    also if you want more than 1 product

     

    function pasteReaction(i,x,y,s,n)

    chance = math.random(-1,1) --1/3 chance of a single product
    type = tpt.get_property("type", x + math.random(-1,1), y + chance)
    if type == tpt.el.watr.id then

    if chance == 1 then
    tpt.parts[i].type = tpt.el.pste.id --first product pste
    end

    if chance == 0 then

    tpt.parts[i].type = tpt.el.acid.id --second acid

    end

    if chance == -1 then

    tpt.parts[i].type = tpt.el.thdr.id --third thdr

    end
    end

    end
    tpt.element_func(pasteReaction,tpt.el.clst.id)

    wow slow typing and look how many comments...

    Edited 3 times by jward212. Last: 24th Sep 2014
  • QuentinADay
    24th Sep 2014 Member 0 Permalink

    wow i love how you added onto what i did it looks pretty good XD

     

    btw you need one more "end" for it to work

    Edited once by QuentinADay. Last: 24th Sep 2014
  • batman333
    24th Sep 2014 Member 0 Permalink

    Thanks everyone!!!

  • QuentinADay
    24th Sep 2014 Member 0 Permalink

    No problem! :)

  • jward212
    24th Sep 2014 Member 0 Permalink

    @QuentinADay (View Post)

     I always make these mistakes with out my lovly notepad++

  • QuentinADay
    24th Sep 2014 Member 0 Permalink

    lol i use sublime text 2 it works really well and i love it