Lua errors

  • sfsjunior
    2nd Nov 2014 Member 0 Permalink

    Hello!

    I'm making a mod in lua and sometimes it NEEDS to change indexes of things and etc. but when something changes, tpt throws only one error(my elements auto-actualize, so it fixes the error).It needs to appear, because the program changes variables during it execution, but there are that ugly messages covering 1/4 of the screen ("autorun.lua:68: <...>"). There is any way to hide the messages (you know, make them not appear in the screen)?

    Thanks very much!

    *Please, don't note the bad english... I'm not native of an english-speaking country

  • jacob1
    2nd Nov 2014 Developer 0 Permalink
    Not sure I understand what the problem is, maybe if you posted the code I could help :)

    Or, you could try using pcall. It's a built in Lua function that ignores all errors. Works like this:

    function potato(arg1, arg2, arg3)
    print("this function does something useful")
    error("but it also errors")
    end
    ret, errr = pcall(potato, arg1, arg2, arg3).

    Note how the first argument to pcall is the function itself, the other are the arguments that get passed into the function.

    Edit: also, pcall returns two values. You can ignore them if you want (doesn't sound like you care about the errors here), but if you want them ret is true if the function worked, and false if it failed. And if it failed err is the error message.
    Edited once by jacob1. Last: 2nd Nov 2014
  • sfsjunior
    2nd Nov 2014 Member 0 Permalink

    @jacob1 (View Post)

     Hello! Sorry, i've not explained very well... It's an element's update function... But very thanks, anyway!

  • jacob1
    2nd Nov 2014 Developer 0 Permalink
    @sfsjunior (View Post)
    ok, you can embed a pcall inside the function. I did that in my script here:


    local rand = elem.allocate("JACOB1", "RAND")
    elem.element(rand, elem.element(elem.DEFAULT_PT_LOLZ))
    elem.property(rand, "Name", "RAND")
    elem.property(rand, "Description", "Every pixel changes into a random element when drawn, fun!")
    elem.property(rand, "Color", 0xFFFE8915)
    elem.property(rand, "MenuSection", elem.SC_SPECIAL)
    elem.property(rand, "Update", function (i)
    function ignore(i)
    tpt.set_property("type", math.random(1,255), i)
    end
    pcall(ignore, i)
    end)


    Edited once by jacob1. Last: 2nd Nov 2014
  • sfsjunior
    2nd Nov 2014 Member 0 Permalink

    @jacob1 (View Post)

     Thanks very much! Worked perfectly! Thanks! Thanks again!

  • NorthMustang
    6th Nov 2014 Member 0 Permalink

    Okay, here's some stuff I can throw out there.

    How do you set the life of your element?

    How do you make an element stick to other elements like gel?

    How do you make an explosive very powerful but not seem to form a white hole on the entire screen when it explodes?

  • jward212
    7th Nov 2014 Member 0 Permalink

    1.tpt.set_property("life", TheValue ,i)

    2.a bit hard tryied it and failed,maybe look at gel in c++ for answers

    3.I made some explosives in my fuel mod produce thdr with a mixture of other things to be more powerful

    function N2O4(i,x,y,s,n)
     ol = math.random(-1,1)

    --ol is a 1/3 chance
     rocket = tpt.get_property("type",x+math.random(-2,2),y+math.random(-2,2))

    --rocket is the type of partical in a 5x5 area with N2O4 being the centre 
     if rocket == Diazane or rocket == tpt.element('plsm') or rocket == tpt.element('fire') or rocket == tpt.element('thdr') then

    --checks if rocket is plsm or fire or diazane(diazane not needed)
      if ol == -1 then

    -- if ol = -1 (1/3 chance)
       sim.partChangeType(i, tpt.element('plsm'))

    --make plasma
      end
      if ol == 0 then

    --another 1/3 chance
       sim.partChangeType(i, tpt.element('thdr'))

    --make thdr for explosiveness
      end
      if ol == 1 then
       sim.partChangeType(i, tpt.element('n2'))

    --other product you may choose
      end
     end
    end
    tpt.element_func(N2O4,DinitrogenTetroxide)

    Edited once by jward212. Last: 7th Nov 2014
  • NorthMustang
    8th Nov 2014 Member 0 Permalink

    @jward212 (View Post)

    I have your "More Fuel Mod", and I've learned quite a bit of how TPT script works with it.

    I do not have a c++ program. Can it be run from drive E? Is it only about 200 mb's so that downloading/installing it won't destroy my pc? If either of these last two questions are true then...

    Where can I find the download for c++?

    Edited 2 times by NorthMustang. Last: 8th Nov 2014
  • jward212
    8th Nov 2014 Member 0 Permalink

    I meant look at TPT's source stuff thats in C++ (can be found at githud https://github.com/simtr/The-Powder-Toy/blob/master/src/simulation/elements/GEL.cpp ). then use it to base your lua script. you might need some knowledge in how to program in C++/C, I know the VERY basics when using C++, but i am learning

  • NorthMustang
    8th Nov 2014 Member 0 Permalink

    @jward212 (View Post)

    Where can I find the c++ download?