Functions inside a lua table

Posted by Ksajal on Thu 01 Apr 2010 11:33 PM — 5 posts, 23,070 views.

#0
It's been driving me insane, I'm using the same way of declaring tables in other modules, but I've never got such an error.

Here it is:


if
	not scan
		then
	scan = {}
end --if


function scan.salve ()
if 
	GetVariable ("salve") == "1" and
	able.to ("apply") and 
	not flags.get ("applying_salve")
		then
--stuff, I don't think it's really relevant
end --if
	
end --function


return scan


Here is where I get the error, at my prompt script (it's executed at the prompt):


package.loaded.scan = nil
require "scan"

function prompt (sName, sLine, wildcards)

--other stuff

scan.salve ()

end --function


The error I get is:

Function/Sub: prompt called by trigger
Reason: processing trigger "Prompt"
[string "Script file"]:5618: attempt to call field 'salve' (a nil value)


I think that somehow the function scan.salve () is not created, next (scan) returns nil

What am I doing wrong?
Amended on Fri 02 Apr 2010 12:04 AM by Ksajal
USA #1
Well... where/how is your code calling 'elixir'? The word 'elixir' doesn't appear in any of the code you showed, just the error message.
#2
David Haley said:

Well... where/how is your code calling 'elixir'? The word 'elixir' doesn't appear in any of the code you showed, just the error message.

Darn, it's the same thing, I have two functions inside scan, one is elixir, the other is scan, they both return the same error message.
I'll edit my previous post
Australia Forum Administrator #3
It worked for me when I tried it so you must be doing something else, such as assigning something to scan, forgetting that it is a module.
#4
Nick Gammon said:

It worked for me when I tried it so you must be doing something else, such as assigning something to scan, forgetting that it is a module.

You were right, I was resetting the scan table later in my script, and it didn't cross my mind to check.

Thank you!