luanub, on 28 December 2012 - 04:00 PM, said:
Using table for the name of the table is probably not the best idea. There is a table API and if you go to use any of the functions(table.insert(), table.remove() etc..) you will probably get errors.
I got in the habbit of using the following naming convention for my vars when I first started using Lua. sMsg would be for a string that holds a message, tMsg for a table that holds a message(s).
He's right. However, an API is actually a table containing functions and constants, at least in Lua.
That naming convention is good, but I personally prefer to just using CamelCap (superAwesomeVariable) because, more often than not, the name of the variable explains its type and thus serves as a good alternative to using the first character of the type in your naming.
On to a solution to your problem.
If these two snippets of code are defined in different files, it would appear that 'table' doesn't appear to be defined and thus the interpreter will assume you're talking about the data contained in the native 'table' table. (As explained by luanub.)
Something that you need to take into consideration is the scope of your program. In this I mean that you have a function called 'variable declare'. When you execute this function, the variables you declare in it are local to the scope of that function and that function only because they haven't been declared in a scope greater than that of the function 'variable declare'. Considering that you reference the variables in other functions, I would suggest that you declare them outside of your functions like the following code would demonstrate:
-- Global scope variable declaration.
local rsInput = "back"
local drone = peripheral.wrap("front")
local x = 38
local y = 38
local table = {x, y}
local droneCount = 0
--[[ From:
function variableDeclare()
rsInput = "back"
drone = peripheral.wrap("front")
x = 38
y = 38
table = {x,y}
droneCount = 0
end--]]
You don't need to worry about these variables being accessible after the execution of your program for two reasons:
1) The shell executes program by using 'dofile' and loading the contents of your program into a function that the shell then executes that function within itself. This means that once your program is executed in the aforementioned function, its variables are garbage collected.
* Important note: Variables that are declared exclusively within a function (no such declaration has been made at a higher scope (global, for example, but not in other functions)) are exclusive to that function and are destroyed once the function is executed.
2) Less importantly, by declaring your variables in YOUR PROGRAM'S GLOBAL SCOPE, you eliminate the ability for other programs to access those variables because their outside of their scope.
Trying to access 'table' in a scope where it isn't defined (as you'd like it to be: there is a native table called 'table') will cause it to be considered a nil value.