Thread Tools Display Modes
09-27-13, 01:13 PM   #1
Resike
A Pyroguard Emberseer
AddOn Author - Click to view addons
Join Date: Mar 2010
Posts: 1,290
To be nil or not to be nil

I have an issue about an user reported possible bug:

Can this line cause an error like that?

Lua Code:
  1. if aura.Timer.enabled then
  2.     --
  3. end

Attempt to index field 'Timer' (a nil value).

Even when the Timer is really nil than why does it pop an error?

I can't reproduce the problem anyhow so i'm not sure what/why is this happening.
  Reply With Quote
09-27-13, 01:19 PM   #2
Rilgamon
Premium Member
 
Rilgamon's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Sep 2009
Posts: 822
A "key" can not be nil.
__________________
The cataclysm broke the world ... and the pandas could not fix it!
  Reply With Quote
09-27-13, 01:45 PM   #3
Haleth
This Space For Rent
 
Haleth's Avatar
Featured
Join Date: Sep 2008
Posts: 1,173
The compiler is looking for the key 'enabled' in the table aura.Timer - only aura.Timer isn't a table, it's nil. That gives an error.
  Reply With Quote
09-27-13, 01:57 PM   #4
zork
A Pyroguard Emberseer
 
zork's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2008
Posts: 1,740
if aura.Timer and aura.Timer.enabled then
...
end
__________________
| Simple is beautiful.
| WoWI AddOns | GitHub | Zork (WoW)

"I wonder what the non-pathetic people are doing tonight?" - Rajesh Koothrappali (The Big Bang Theory)
  Reply With Quote
09-27-13, 02:05 PM   #5
Resike
A Pyroguard Emberseer
AddOn Author - Click to view addons
Join Date: Mar 2010
Posts: 1,290
Originally Posted by Haleth View Post
The compiler is looking for the key 'enabled' in the table aura.Timer - only aura.Timer isn't a table, it's nil. That gives an error.
But when the Timer is nil then the Timer.enabled is not gonna be nil?
  Reply With Quote
09-27-13, 02:18 PM   #6
Haleth
This Space For Rent
 
Haleth's Avatar
Featured
Join Date: Sep 2008
Posts: 1,173
You can't treat a nil value (Timer, in this case) as a table.

You have to make sure that it isn't nil before you start to do table lookups (Timer.enabled).
  Reply With Quote
09-27-13, 02:22 PM   #7
Resike
A Pyroguard Emberseer
AddOn Author - Click to view addons
Join Date: Mar 2010
Posts: 1,290
Originally Posted by Haleth View Post
You can't treat a nil value (Timer, in this case) as a table.

You have to make sure that it isn't nil before you start to do table lookups (Timer.enabled).
I see, my bad then.
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » To be nil or not to be nil


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off