Addon making

A place to post your add ons and ideas for them

Moderator: Moderator

Post Reply
Message
Author
Anorak
Posts: 1
Joined: Tue Jun 19, 2018 11:04 am

Addon making

#1 Post by Anorak »

So i was really tempted to make addons for this game as i really like the current ones being posted and the ones that i am using but i have looked it up and how to make said addons but i dont know where to get started, so my question to you guys(addon makers) what programming language(i write in C) would i need for addon making.

Lokean
Halfling
Posts: 88
Joined: Sun Dec 10, 2017 12:27 am

Re: Addon making

#2 Post by Lokean »

The actual engine is written in C, but the development environment is all in Lua. I came into Lua cold in November (from C++ and java) and estimate it took me five weeks or so to grok Lua and maybe another couple of months to have the paradigms for the Tome Engine mostly down. The T-Engine implementation of Lua treats it like an object oriented language, with inheritance and so on. The two fundamental first-class composite types that you need to mess with are functions and tables (tables consist of an array-like indexable section plus a hash table spliced together). Everything is effectively passed by value, but 'table and function variables are references' (as Lua folk seem to like saying). The variable actually behaves as if it contained a pointer, but treated it as a value, so that if you pass a table/function/table-but-pretending-its-an-object to a function it will modify the original, but if you re-assign it won't overwrite the original. That is to say:

Code: Select all

local x = 0 - primitives are passed by value
local foo = {bar = "baz"}  -- make a hash table with key["bar"] containing value "baz", this will be passed 'by value' but the 'value' is actually a pointer (ish)

function wipeFoo(x, foo)
  x = 1
  foo.bar = 10
  foo = {}
end

wipeFoo(x, foo)
print(x) -- spits out 0, the local x from the function is out of scope now
print(foo.bar) -- spits out 10, because the function modified a value inside the table.
               -- The locally-assigned empty table from the function is out of scope, but the original table wasn't overwritten by foo = {}
               -- instead, a new empty table was instantiated, and its pointer was assigned to the local variable foo inside the function
               -- leaving the original table alone (and effectively out of scope of the function at that point)

astralInferno
Uruivellas
Posts: 834
Joined: Mon Jan 27, 2014 10:40 am

Re: Addon making

#3 Post by astralInferno »

having never done ANY coding before, I managed to learn to make tome addons exclusively by looking at existing mods and doing lots of copy pasting and editing. It's pretty easy to deal with! :)

Effigy
Uruivellas
Posts: 970
Joined: Fri Oct 10, 2014 4:00 pm

Re: Addon making

#4 Post by Effigy »

Lua does allow calling C code, but in general the game logic is written in Lua. The language is designed to be user friendly so it shouldn't take too long to learn for an experienced programmer. I would say the more time-consuming parts is getting familiar with the ToME/T-Engine code base. Most of it is reasonably well documented, but it does take a while to get used to.

As Lokean said, Lua has first-class functions and tables, which are awesome by the way. You can assign functions to variables and pass as arguments (including anonymous functions) without the ugly syntax of C function pointers. Tables are the primary data structure, which can behave as either 1-indexed arrays or hash maps with mixed-type keys, or a combination of the two. The language isn't object-oriented by default, but the T-Engine implements its own class system. It's a shame Lua isn't more popular because it's a really powerful language with nice syntax and is relatively performant for an interpreted language; I suspect the lack of a built-in class system and its minimalist standard library makes it less popular than Python and comparable languages.

The ToME IRC channel is a good place to hang out and ask questions about making addons and Lua in general. Apparently there's an official ToME Discord channel as well, although I haven't be in there yet.

Post Reply