View Full Version : attempt to index field `?' (a nil value)
Eternalydead
23-09-2006, 11:51 PM
Ok, here's the problem. I'm trying to write an AddOn, everything is looking fine, until I log in and see "Interface\AddOns\AutoAccept\AutoAccept.lua:100: Attempt to index field `?' (a nil value)". Here's an excerpt of my .lua file from lines 99 - 104
function AutoAccept_ShowStatus()
if (AutoAcceptOptions[Realm][Player].Enabled ) then
DEFAULT_CHAT_FRAME:AddMessage(AA_STATUS_ON);
if (AutoAcceptOptions[Realm][Player].Mode == 'friend') then
DEFAULT_CHAT_FRAME:AddMessage(AA_FRIEND_MODE);
end.
I have the functions set up right in the beginning (I believe) and I have them set to run on event PLAYER_ENTERING_WORLD. Any Help is appreciated.
xbjim
25-09-2006, 11:02 AM
my guess is either Realm or Player is nil on the the 2nd line you have:
if (AutoAcceptOptions[Realm][Player].Enabled ) then
edit; its hard to tell why without seeing the entire thing :(
Eternalydead
25-09-2006, 11:46 PM
Part where it registers the commands:
local function AutoAccept_InitializeSetup()
Player=UnitName("player");
Realm=GetCVar("realmName");
if AutoAcceptOptions[Realm] == nil then
AutoAcceptOptions[Realm] = {}
end
if AutoAcceptOptions[Realm][Player] == nil then
AutoAcceptOptions[Realm][Player] = {};
AutoAcceptOptions[Realm][Player].Enabled = true;
end
if (AutoAcceptOptions[Realm][Player].Mode == nil) then
AutoAcceptOptions[Realm][Player].Mode = 'none';
end
if (AutoAcceptOptions[Realm][Player].DeclineMode == nil) then
AutoAcceptOptions[Realm][Player].DeclineMode = 'none';
end;
if (AutoAcceptOptions[Realm][Player].GuildList ~= nil) then
AutoAcceptOptions[Realm][Player].GuildList = nil;
end;
end;
Lines 99-104, 100 giving me trouble:
function AutoAccept_ShowStatus()
if (AutoAcceptOptions[Realm][Player].Enabled ) then
DEFAULT_CHAT_FRAME:AddMessage(AA_STATUS_ON);
if (AutoAcceptOptions[Realm][Player].Mode == 'friend') then
DEFAULT_CHAT_FRAME:AddMessage(AA_FRIEND_MODE);
end
hopefully this helps.
xbjim
26-09-2006, 12:51 AM
AutoAcceptOptions[Realm][Player].Enabled
realm or player is nil, but i cant reproduce it :(
ill try making some code thats doing what your trying =/
Sherkhan
26-09-2006, 12:59 AM
Hmmm, maybe GetCVar is not working correctly ? You could try using GetRealmName() instead.
xbjim
26-09-2006, 01:07 AM
ok this works for me:
AutoAccept.toc
## Interface: 11200
## Title: AutoAccept
## SavedVariables: AutoAcceptOptions
AutoAccept.xml
AutoAccept.xml
<Ui xmlns="http://www.blizzard.com/wow/ui/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.blizzard.com/wow/ui/ C:\Projects\WoW\Bin\Interface\FrameXML\UI.xsd">
<Script file="AutoAccept.lua"/>
<Frame name="AutoAcceptFrame" hidden="true">
<Scripts>
<OnLoad>
AutoAccept_OnLoad();
</OnLoad>
<OnEvent>
AutoAccept_OnEvent(event, arg1, arg2, arg3);
</OnEvent>
</Scripts>
</Frame>
</Ui>
AutoAccept.lua
local AA_STATUS_ON = "AutoAccept Enabled.";
local AA_STATUS_OFF = "AutoAccept Disabled.";
local AA_FRIEND_MODE = "AutoAccept Mode: Friend";
local function AutoAccept_InitializeSetup()
Player=UnitName("player");
Realm=GetCVar("realmName");
if AutoAcceptOptions == nil then
AutoAcceptOptions = { };
end
if AutoAcceptOptions[Realm] == nil then
AutoAcceptOptions[Realm] = {}
end
if AutoAcceptOptions[Realm][Player] == nil then
AutoAcceptOptions[Realm][Player] = {};
AutoAcceptOptions[Realm][Player].Enabled = true;
end
if (AutoAcceptOptions[Realm][Player].Mode == nil) then
AutoAcceptOptions[Realm][Player].Mode = 'none';
end
if (AutoAcceptOptions[Realm][Player].DeclineMode == nil) then
AutoAcceptOptions[Realm][Player].DeclineMode = 'none';
end;
if (AutoAcceptOptions[Realm][Player].GuildList ~= nil) then
AutoAcceptOptions[Realm][Player].GuildList = nil;
end;
end;
function AutoAccept_ShowStatus()
if (AutoAcceptOptions[Realm][Player].Enabled ) then
DEFAULT_CHAT_FRAME:AddMessage(AA_STATUS_ON);
else
DEFAULT_CHAT_FRAME:AddMessage(AA_STATUS_OFF);
end
if (AutoAcceptOptions[Realm][Player].Mode == 'friend') then
DEFAULT_CHAT_FRAME:AddMessage(AA_FRIEND_MODE);
end
end
function AutoAccept_OnLoad()
this:RegisterEvent("ADDON_LOADED");
end
function AutoAccept_OnEvent(event, arg1, arg2, arg3)
if event == "ADDON_LOADED" and arg1 == "AutoAccept" then
AutoAccept_InitializeSetup();
AutoAccept_ShowStatus();
end
end
and it created this in WTF\Account\[account]\SavedVariables\AutoAccept.lua
AutoAcceptOptions = {
["REALM"] = {
["PLAYER"] = {
["Enabled"] = true,
["DeclineMode"] = "none",
["Mode"] = "none",
},
},
}
of course REALM and PLAYER are the real stuff, i just edited that. so it should work.
vBulletin® v3.8.4, Copyright ©2000-2009, Jelsoft Enterprises Ltd.