Jump to content




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


3 replies to this topic

#1 qwerty

  • Members
  • 72 posts
  • LocationThe Sand Dunes

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 by qwerty, 25 February 2020 - 03:32 PM.


#2 Lupus590

  • Members
  • 2,029 posts
  • LocationUK

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?

#3 Stekeblad

  • Members
  • 62 posts
  • LocationSweden

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 by Stekeblad, 25 February 2020 - 11:21 AM.


#4 qwerty

  • Members
  • 72 posts
  • LocationThe Sand Dunes

Posted 25 February 2020 - 12:44 PM

View PostLupus590, on 25 February 2020 - 11:12 AM, said:

You have a variable name collision, using local variables will help.
k, thanks. I'm realy inexperienced with tables

View PostLupus590, on 25 February 2020 - 11:12 AM, said:

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-

View PostLupus590, on 25 February 2020 - 11:12 AM, said:

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

View PostStekeblad, on 25 February 2020 - 11:16 AM, said:

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 by qwerty, 25 February 2020 - 12:45 PM.






2 user(s) are reading this topic

0 members, 2 guests, 0 anonymous users