ToME: the Tales of Maj'Eyal

Addon making
Page 1 of 1

Author:  Anorak [ Tue Jun 19, 2018 11:08 am ]
Post subject:  Addon making

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.

Author:  Lokean [ Tue Jun 19, 2018 8:51 pm ]
Post subject:  Re: Addon making

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:
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 = 10
  foo = {}

wipeFoo(x, foo)
print(x) -- spits out 0, the local x from the function is out of scope now
print( -- 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)

Author:  astralInferno [ Wed Jun 20, 2018 1:28 am ]
Post subject:  Re: Addon making

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! :)

Author:  Effigy [ Wed Jun 20, 2018 3:36 am ]
Post subject:  Re: Addon making

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.

Page 1 of 1 All times are UTC
Powered by phpBB® Forum Software © phpBB Group