• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

[Lua] Tips & Tricks

Syntax

Developer
Joined
Oct 10, 2007
Messages
2,890
Reaction score
458
Location
Texas
Just a simple thread where we can post Lua tricks, and some tips that the lua documentation is unclear on.

Trick #1: Swapping variables

local a, b = b, a

Tip #1: Difference between ipairs and pairs

Lua:
local foodTableIPAIRS = {"banana", "banana", "vegetable"}
local foodTablePAIRS = {["apple"] = "fruit", ["banana"]="fruit", ["lettuce"]="vegetable"}
 
print("Pairs:\n")
for k, v in pairs(foodTablePAIRS) do
    print(k .. " = " .. v .. "\n")
end
print("\nIpairs:\n")
for k, v in ipairs(foodTableIPAIRS) do
    print(k .. " = " .. v .. "\n")
end

output:
Pairs:
apple = fruit
banana = fruit
lettuce = vegetable

Ipairs:
1 = fruit
2 = fruit
3 = vegetable
 
Last edited:
yah sorry the script wasn't really clear on the type of table needed. I updated the script to show this.
 
Are you trying to get some respect back after leaving for V.Apus? You keep making all of these threads all of a sudden, out of no where "there's Syntax!" :)

Welcome back, and thanks for helping.

Good luck.
 
no... I still support VAPus and I'm a global mod over there. I used to make threads like this all the time. It just so happens I have alot of free time :p
 
Quick question sorry im new to scripting how does the output show the print function? In the tibiaclient chatbox like a normal message?
 
Quick question sorry im new to scripting how does the output show the print function? In the tibiaclient chatbox like a normal message?
No, it'd print it on TFS console, iirc.
 
Back
Top