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

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
JeanFant
Prole
Posts: 2
Joined: Wed May 20, 2020 12:21 pm

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

Post 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'
User avatar
pgimeno
Party member
Posts: 3544
Joined: Sun Oct 18, 2015 2:58 pm

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

Post by pgimeno »

Can you show the first three lines of "var.lua" to us?
JeanFant
Prole
Posts: 2
Joined: Wed May 20, 2020 12:21 pm

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

Post 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.
MrFariator
Party member
Posts: 509
Joined: Wed Oct 05, 2016 11:53 am

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

Post 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.
Post Reply

Who is online

Users browsing this forum: Google [Bot] and 47 guests