This isn't a question, it's just a very niche technical note that I though worth making (and this probably isn't news to seasoned modders).
The SWBF2 lua interpreter runs lua version 5.0.2.
There's an easy way to check this, because all lua interpreters store the lua version in a global variable called
_VERSION so you can just throw this print command in a mission lua, and it will print the lua version to the debug log:
Code: Select all
print("The SWBF2 lua interpreter uses:", _VERSION)
A word to the wise (ie anyone who goes looking for lua guides, either online or in books), there are some notable differences between lua 5.0, lua 5.1, lua 5.2 and so on. For example, if you want to find the length of a table in lua 5.0 you would do this:
Code: Select all
local example = {1, 2, 4}
local length = table.getn(example)
But in lua 5.1 and beyond, you would do this:
Code: Select all
local example = {1, 2, 4}
local length = #example
^ This does not work in SWBF2, because this
# syntax wasn't added until lua 5.1 (and
table.getn was removed in lua 5.2). That might be the best example because if anyone is trying to figure out how to do something and they go looking on stack exchange, or in a textbook etc, they'll notice
# is used very liberally now. (Not that I know much about lua, but I don't recommend swapping
#t with
table.getn(t) for everything it's used for now. There's probably a tidier way to write the code in lua 5.0). Supposedly lua 5.2 came with some fairly significant changes too but I'm not familiar enough with lua to say what they are. The addition of a
goto statement was one; you can't use that in SWBF2.
So that's just something to keep in the back of your mind. A final note is that lua.org have their own textbook on lua called
Programming in Lua. They host the first edition of that book for free online, and by fortunate coincidence, the first edition specifically is the edition released for lua 5.0. (It's less good news if you want a printed copy, because the first edition is the hardest to find). But I've found the online version at least to be a good resource for modding SWBF2.