Im working on a script to control my turtle with chat commands. it is working good so far but i wonder if there is a better solution.
I use two tables at the moment cause i want the system to be flexible. so that you can easily change the commands for each action.
so this is how it looks at the moment.
the index of both tables is the same. you could say its the description of the command.
then the table tcom holds the Commands and tfunctions holds the function which is executed when the command is used.
local tcom = {}
tcom["up"] ="rauf"
tcom["down"] = "runter"
local tfunctions = {}
tfunctions["up"] = moveUp
tfunctions["down"] = moveDown
then i check the command with the tcom table and if it gets a match i call the function from the functions table with pcall.
for k,v in pairs(tcom) do
if v == commands[2] then
pcall(tfunctions[k],tonumber(commands[3]))
end
end
now i would like to know if this solution is good or if i could do it better in a different way. maybe just using one table.
another question is i heard using to many functions can make problems. is this true and if so what is too many?
thanks for your help and greets
Loki