New elements made via Lua

  • Videogamer555
    26th Dec 2011 Member 0 Permalink
    We need to be able to make temporary elements via Lua. It would work by duplicating an existing element to create a new one with the same properties but a different name. Then you'd use use other already available Lua commands to "reprogram" this new element. For example, I could make a separate element which is flamable metal. like this.

    tpt.newelem.metl "FMTL", 1
    This will duplicate the element metal and call the new elmenent FMTL, and assign it to menu 1 (the electronics menu). As it is not a hardcoded element it will not survive closure of TPT, so if you want it more perminent, you'd put that line of code in autorun.lua (and in fact for technical reasons it MUST be in autorun.lua as I'll explain later).

    It will be EXACTLY identical to METL, so then to reprogram it to make it flammable, you'd add this line of code after the element creation line.
    tpt.elem.fmtl.flammable=50
    This line makes it so it can catch fire. Remember this will need to be in autorun.lua so it can be permanent if you want it to be (and in fact for technical reasons it MUST be in autorun.lua as I'll explain later).

    Now since it isn't hardcoded into TPT it can't have a fixed element index number. So what TPT will do when executing that Lua code will be to first look in the hardcoded elements and autodetect the highest element index number and then assign an index number 1 higher than that. If there is more than one user-defined element in autorun.lua, it will first check the normal elements and any preexisting user-defined ones which had been added earlier in the script, and use whatever the next available unused index number and assign it to the element being created at that moment.

    Lets say there are 150 elements (not sure how many there are, this is just a guess) in TPT from 0 to 149, and then you assign 5 more in your autorun.lua. So here's a sample of autotrun.lua:

    tpt.newelem.metl "MET1", 1
    tpt.newelem.metl "MET2", 1
    tpt.newelem.metl "MET3", 1
    tpt.newelem.metl "MET4", 1
    tpt.newelem.metl "MET5", 1

    It will parse it like this:

    Read line tpt.newelem.metl "MET1", 1
    Check next available element number and discover next elem number is 150
    Make MET1 and assign it element number 150
    Read line tpt.newelem.metl "MET2", 1
    Check next available element number and discover next elem number is 151
    Make MET2 and assign it element number 151
    Read line tpt.newelem.metl "MET3", 1
    Check next available element number and discover next elem number is 152
    Make MET3 and assign it element number 152
    Read line tpt.newelem.metl "MET4", 1
    Check next available element number and discover next elem number is 153
    Make MET4 and assign it element number 153
    Read line tpt.newelem.metl "MET5", 1
    Check next available element number and discover next elem number is 154
    Make MET5 and assign it element number 154


    Now this MUST be done by autorun.lua or it won't work, because element loading (and in this case element creation) is something done very early in the program execution.



    So developers do you think this idea has any possibility in the actual TPT. I REALLY REALLY REALLY REALLY hope this is possible so I can make my own magnesium and other elements which have been "rejected" for being in the official version of TPT, without me having to learn C programming (something that I think I probably won't ever achieve as I've tried repeatedly in the past and have failed every single time, but Lua on the other hand seems very easy).
  • ZER02541714
    26th Dec 2011 Member 0 Permalink
    I keep getting an error
  • MasterMind555
    26th Dec 2011 Member 0 Permalink
    @Videogamer555 (View Post)
    This was already suggested, please use the search bar.
    If you "REALLY REALLY REALLY REALLY" want it, make it yourself in C.
  • Videogamer555
    26th Dec 2011 Member 0 Permalink
    There is no technical reason why this would not work. I can see that other implementations of it via Lua or other techniques won't work, but I described in great detail here exactly how the feature is to be implemented to show the developers 2 things:
    1) That it CAN be implemented in a way that actually works.
    2) Just that implementation would work (using some pseudo code examples).

    This should be enough for a trained developer to actually implement it upon reading my suggestion.

    What I REALLY want to hear is not from TPT users. I want to have an official developer post their reply in here.

    Also your suggestion that I should "make it yourself in C." COMPLETELY IGNORES the last sentence in the thread's opening post which states that "something that I think I probably won't ever achieve as I've tried repeatedly in the past and have failed every single time, but Lua on the other hand seems very easy". This alone should be a motivational sentence to any developer as a good reason to implement this feature.
    Said reason is to give ordinary users (such as myself) about half of the capability of a developer using Lua alone (no C needed).
  • jacob1
    26th Dec 2011 Developer 0 Permalink

    This does seem usefull. I will try to add it to my mod someday, unless one of the official devs tries to add it.

    The only problem I could see with this is that you can't change PT_NUM, and you can't ever have more than 256 elements no matter what, so you would have to find a way around that. There might have to be a limit to how many elements you can create. Also, you won't need to set which menu an element goes into, because that is one of the properties of the element that would be copied.

  • Videogamer555
    26th Dec 2011 Member 0 Permalink

    jacob1:

    This does seem usefull. I will try to add it to my mod someday, unless one of the official devs tries to add it.

    The only problem I could see with this is that you can't change PT_NUM, and you can't ever have more than 256 elements no matter what, so you would have to find a way around that. There might have to be a limit to how many elements you can create. Also, you won't need to set which menu an element goes into, because that is one of the properties of the element that would be copied.



    No you wouldn't have to find a way around it. Once the official TPT reaches 256 elements this feature becomes useless. But BEFORE THEN we still have quite a few empty spots. And I'd recommend that the developers save 10 empty slots for user defined elements instead of just filling them all up with official elements.
  • ForumTroll
    26th Dec 2011 Banned 0 Permalink
    This post is hidden because the user is banned
  • therocketeer
    26th Dec 2011 Member 0 Permalink
    @Videogamer555 (View Post)
    There could be like a favourites menu, but with elements you make via Lua. I like the idea, could see it in the future.
    @everyone
    Remember, nothing is impossible when it comes to programming.
  • Simon
    26th Dec 2011 Administrator 0 Permalink
    @Videogamer555 (View Post)
    There is no technical reason why this would not work.
    Yes, there is. The total number of elements is hard-coded, It cannot be changed at runtime.
  • code1949
    26th Dec 2011 Member 0 Permalink
    @ForumTroll (View Post)
    That only uses one element slot. Plus it is used constantly as a temperature manipulator.