TTS Scripting

Tabletop Simulator is a great way to play and interact with virtual board games. However, it gets even better with the extreme level of customization that it offers! In addition to custom pieces and figurines, you can use the Lua Scripting Language and XML/HTML to further customize the experience.

Here is a quick crash course:



Q: What is Lua?
A: It is a programming language written by a university team in Brazil. According to their website it is the most used video game scripting language. Games like Angry Birds and World of War Craft use it as well. For me it reminds me a lot of the JavaScript programming language. 

Q: What can I do with Lua in Tabletop Simulator?
A: Put messages in player chat, keep track of things like dice, automate setups, etc.

Q: What is HTML / XML?
A: HTML is a markup language. This means it tells an application like your Web Browser how the information should be presented or displayed (over simplification). XML is a focus more on the storage of data and how it is structured. To paraphrase www.javatpoint.com, "HTML focuses on how the data looks while XML focuses on how the data is stored."

Q: What can I do with HTML / XML in Tabletop Simulator?
A: Create custom windows, Ask Users / GM for feedback, create visual overlays, store information, etc

Let's get familiar with the scripting interface:
  1. Create a new Single Player game in Tabletop Simulator.

  2. From the top menu choose Modding / Scripting.

  3. The Global scripting window will appear. As the names implies this will affect everything and is where you put general code.

    There are two sides:
    Lua (for Lua scripting code)
    UI (for custom interfaces with HTML / XML)


  4. Drag some objects into your game. Right-click on one and choose Scripting / Scripting Editor from the context menu.


    Here we have a similar scripting window as before, however, this now applies only to this object.


  5. Notice the GUID number of "e06335". We can use this later as a Globally Unique Identifier of this object. In other words whenever we reference "e06335" we will be referencing this exact object.

    At this point you can just copy / paste in some code that you find on the Internet and be good to go!

  6. Let's look at some Global Lua code together in a nicer editor like Notepad++ or Atom:


    This is Lua code:
    • Functions start with "function", name the function, and end with "end". This is how we create a block of code and then call (execute) it later on.
    • Comments (just for the programmer, but don't affect the execution of the code) have "--" in-front of them. This can also be used to disable things without removing it from the code.
    • If Then Statements start with "if" and end with "end". These are great for evaluating things.

  7. Let's look at some Object Lua code together:


    This is more Lua code:
    • By using "self." we reference this object that we have highlighted.
    • Be careful about declaring variables here as they might only be local to this object and not visible by anything else.

  8. Let's look at some Global XML code together:


    This is XML markup:
    • Datapoint Tags start with "<" and end with "/>".
    • Comments start with "<!--" and end with "-->"
    • Here we are creating a custom UI window that will be visible on the screen.
    • We are able to handle events like "onClick" so that something can happen when a UI element is clicked.

  9. If your script directly loads UI object/elements (like images) then you must load them under Modding / Scripting / Custom UI Assets (Hammer / Wrench icon) / Plus Sign icon.


    In this example I load the first graphic as "page1".
I hope with this crash course you have many of the tools needed to get started!
For more information there is a lot of great documentation here: https://api.tabletopsimulator.com

Comments

Popular Posts