This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
qwerty's profile picture

[SOLVED]attempt to call global 'index' a table value.

Started by qwerty, 25 February 2020 - 09:46 AM
qwerty #1
Posted 25 February 2020 - 10:46 AM
that is the error I'm getting from this;


function index()
  if index ~= nil then
	index = nil
	index = inventory.list()
  else inventory.list()
  end
end
why is that?
as the name implies this is just a function used to update the index table of all items inside a chest.
Edited on 25 February 2020 - 02:32 PM
Lupus590 #2
Posted 25 February 2020 - 11:12 AM
You have a variable name collision, using local variables will help.

Side note, what is the goal of that function?

Also, are all these ask a pro posts you are making the same program?
Stekeblad #3
Posted 25 February 2020 - 11:16 AM
You are overwriting your function and turning it into a table, when you try calling the function again it fails because its not a function anymore.


function index()
    index = {}
end
print("index is a " .. type(index))
index() -- ok
print("index is a " .. type(index))
index() -- fails, index is a table, not a function anymore
Edited on 25 February 2020 - 10:21 AM
qwerty #4
Posted 25 February 2020 - 12:44 PM
You have a variable name collision, using local variables will help.
k, thanks. I'm realy inexperienced with tables

Side note, what is the goal of that function?
it is to index an inventory i.e. chests or storage crates -is for a storage management program-

Also, are all these ask a pro posts you are making the same program?
maybe… maybe not.

You are overwriting your function and turning it into a table, when you try calling the function again it fails because its not a function anymore.
thanks, I really needed you to point that out… that's exactly my issue

with kind regards
-qwerty
Edited on 25 February 2020 - 11:45 AM