Could someone help me learn TPT modding?

  • RedVelvetCake
    29th Jul 2017 Member 0 Permalink

    I have no idea anything about modding in TPT and i want to start. I have it installed on my computer and i have Notepad++ if that helps. Lets say i want to make a new element with absolutely zero knowledge on modding this 'game', where would i start.



    Thanks in advance.

  • QuanTech
    29th Jul 2017 Member 0 Permalink

    @RedVelvetCake (View Post)

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

    Knowing more lua definitely helps. That link is the TPT Lua element creation API's reference.

    Edited 2 times by QuanTech. Last: 29th Jul 2017
  • RedVelvetCake
    29th Jul 2017 Member 0 Permalink

    But where would i start if i wanted to learn how to use the LUA API, also what is the LUA API even used for?

    Edited once by RedVelvetCake. Last: 29th Jul 2017
  • Alexwall
    29th Jul 2017 Member 0 Permalink
    This post has been removed by jacob1: unhelpful
  • Mrprocom
    30th Jul 2017 Moderator 0 Permalink
    @RedVelvetCake (View Post)
    Since you already know Lua (it's not LUA by the way, it's not an abbreviation), it should be very easy for you to get started.
    I recommend you skim over boxmein's Lua API reference before you start making your script, it will help you become more familiar with the API.

    If you don't want to rush things, you can also take a look at this wiki page which contains even more functions than @boxmein's reference with example codes on a lot of them, I mainly use boxmein's reference because it's easy to quickly find stuff there, but if there is a function that is unclear, I could always try to find it in the wiki and see if there are example codes and a more detailed explanation.

    Also to answer your question, the Lua API for TPT provides Lua objects and functions to interact with different aspects of the game, it's like a toolbox that contains various tools you could use to work on whatever you want to work on.

    Example script: Random Save Viewer


    I won't jump immediately into making new elements, you are new to Lua scripting in TPT, so I will give a much easier example.
    Let's say we want to make a new keyboard shortcut that opens a random save, we will make it very basic, let's brainstorm how we want it to work:
    1. First, it looks for a keydown event (when the user pressed down a key) and then executes a function. If we search through boxmein's reference, we will find tpt.register_keypress, which does exactly that.
    2. In the function that gets executed, it should check what key was pressed, we don't want a random save to be viewed when the user presses any key. Let's make the keyboard shortcut simple and make it the key [J] since it's not used.
    3. If the pressed key was [J], generate a random number (let's say from 0 to 2 million), this is done purely in Lua.
    4. Open the save with the ID of that random number we generated, we can use sim.loadSave for that.

    That's pretty much it, now that we have brainstormed everything, we can start coding, since you know Lua, this should be straightforward, here is the code I came up with: https://pastebin.com/TfQTzZUw
    Of course, this is not perfect, it does not check if a save is a 404 save, but this just a basic example.

    Making New Elements


    For this, you pretty much need to allocate your element and set a bunch of properties to it like colour, name, description, etc, then you make the update function, which gets run every frame, this is where you put your reactions and stuff. I don't think I will do a good job at explaining this, so you can head over to that wiki page QuanTech linked.

    A very simple example code is the Random Element script made by @jacob1, I recommend inspecting the source code.

    The reason why I didn't explain making new elements right away and started with a simple example code is because you seem new to this whole thing, so it's better to get you started with simple things first. Good luck, and if there are any problems you encounter while coding, you can always make a new thread about it. Oh and you don't have to memorise all functions, you could always have the reference and the wiki opened and search in them whenever there is a function you are looking for.
  • Potbelly
    15th Aug 2017 Banned 0 Permalink
    This post is hidden because the user is banned