Please explain this.

  • Videogamer555
    27th Dec 2011 Member 0 Permalink
    Please someone explain how this code works. It was posted in another thread by Simon in response to me asking about how to make something burn hot but slow. But I'm confused about some of the lines of Lua code here.
    Maybe someone here can explain just how it works.

    Simon:

    @Videogamer555 (View Post)
    vanquish pretty much said it, the only way you're going to get something to burn hot, very slowly is if you create your own element update function, example
    math.randomseed(os.time())
    function magn_update(i, x, y, s, n)
    next = tpt.get_property("type", x+math.random(-1, 1), y+math.random(-1, 1))
    if next == tpt.el.fire.id or next == tpt.el.plsm.id then
    tpt.parts[i].type = tpt.el.plsm.id
    tpt.parts[i].life = 300
    tpt.parts[i].temp = 5000
    end
    end
    tpt.element_func(magn_update, tpt.el.dmnd.id)
    This would make diamond burn with a hot, plasma flame.



    What does the i, s, and n do in the command magn_update(i, x, y, s, n)?
    Why doesn't this use the "register function" statement?

    If I wanted to have it ignite in response to heat above a certain temperature, not just in response to the presence of fire or plasma, what would I add to this line of code?
    if next == tpt.el.fire.id or next == tpt.el.plsm.id then

    Or what if I wanted it to ignite in response to fire or plasma, but only after it first reached a certain minimum temperature?
  • mniip
    27th Dec 2011 Developer 0 Permalink
    i is I'd
    S and n are unused

    And if you want it too response for temp use:
    if next == tpt.el.fire.id or next == tpt.el.plsm.id or parts[i].temp>1000 then
  • Videogamer555
    27th Dec 2011 Member 0 Permalink
    Which is the faster (processed faster by TPT) command for getting temperature data?
    tpt.get_property("temp", i)
    or
    parts[i].temp
  • jenn4
    27th Dec 2011 Member 0 Permalink
    @Videogamer555 (View Post)
    parts[i].temp is faster to write, and easier to remember.
  • Simon
    27th Dec 2011 Administrator 0 Permalink
    @jenn4 (View Post)
    parts[i].temp is actually slightly slower, use get_property and set_property when you need performance (e.g. you do it a lot), they also take x and y coordinates whereas parts[i] is just an index. parts[i] is still a lot more readable and since we only use it 3 times under a condition, it shouldn't slow the game down too much.
  • Videogamer555
    27th Dec 2011 Member 0 Permalink
    Also what's the difference between
    parts[i].temp
    and
    tpt.parts[i].temp
    ?
  • mniip
    27th Dec 2011 Developer 0 Permalink
    first is nil
    second is temp of Ith particle
  • keperitan
    27th Dec 2011 Member 0 Permalink
    @Videogamer555 (View Post)
    Did you read my response to your previous topic? anyway, I'll repost for your benefit. As you can see, you set several functions between the start of your function and the rest of the code. The symbol for greater than or equal to is >=. for tpt.get_property, the first variable is the property to get, and the next two are the coordinates to look. Enclose any non-numerals or non-functions in double quotes. Remember, the loop used here is a if...then...end loop. I have added spacing to the code to make it more understandable. You may also refer to my realistic diamond code.

    math.randomseed(os.time())
    function magn_update(i, x, y, s, n)

    next = tpt.get_property("type", x+math.random(-1, 1), y+math.random(-1, 1))
    blah =  tpt.get_property("temp", x+math.random(-1, 1), y+math.random(-1, 1)) 

    if next == tpt.el.fire.id or next == tpt.el.plsm.id or blah >= yourtemp then

    tpt.parts[i].type = tpt.el.plsm.id
    tpt.parts[i].life = 300
    tpt.parts[i].temp = 5000

    end

    end
    tpt.element_func(magn_update, tpt.el.dmnd.id)

    Change yourtemp to anything you like. Change the SECOND 'OR' on the if..then line to 'AND' if you want it to respond to fire or plasma above a certain temperature, or let it be if you want these conditions to be mutually exclusive.