Page 1 of 1

attempt to index field 'graphics' (a nil value)

Posted: Wed May 20, 2020 12:29 pm
by JeanFant
Hello, I am starting with love2d and I have a problem, I have an error but I do not know what it means. Thanks in advance and google translation.

The mistake:

Code: Select all

Error: [string "boot.lua"]:530: var.lua:3: attempt to index field 'graphics' (a nil value)
stack traceback:
	[string "boot.lua"]:777: in function <[string "boot.lua"]:773>
	[C]: in function 'error'
	[string "boot.lua"]:530: in function <[string "boot.lua"]:380>
	[C]: in function 'xpcall'
	[string "boot.lua"]:787: in function <[string "boot.lua"]:780>
	[C]: in function 'xpcall'

Re: attempt to index field 'graphics' (a nil value)

Posted: Wed May 20, 2020 2:55 pm
by pgimeno
Can you show the first three lines of "var.lua" to us?

Re: attempt to index field 'graphics' (a nil value)

Posted: Wed May 20, 2020 4:02 pm
by JeanFant
I have found the problème and fix it sorry, the error came from trying to load an image for a variable in a script and using it with the same variable from another script, apparently it doesn't work. If it is supposed to work please help me.

Re: attempt to index field 'graphics' (a nil value)

Posted: Wed May 20, 2020 5:32 pm
by MrFariator
It is possible to access data contained in variables across multiple scripts. However, consider the following:

Code: Select all

-- in script1.lua
myVariable1       = 1 -- 'local' keyword is not used; the variable is now a global
local myVariable2 = 2
-- in script2.lua
print(myVariable1) -- prints 1
print(myVariable2) -- prints nil
In the above example myVariable2 is a local, and so is only available in the scope in which it is defined (in this case, at the root level of the script1.lua file). Meanwhile, myVariable1 gets defined as a global, so it is accessible everywhere in lua code (except different threads). Additionally, script1.lua must be run first before script2.lua, otherwise both myVariable1 and myVariable2 will get printed as nil.

If you provide code to illustrate what you're trying to do, perhaps we can give you some help.