Quote:
Originally Posted by Olenn
You guys are awesome, but I think I am starting to get all of your advice mixed up. I am going to post both Lua scripts and see what you think. I am getting an error;
attempt to index Data a nil value
|
I see 2 potential problems, did the error mention what line was causing the issue? Off the top of my head the issue could be:
Here:
Code:
if (Plugins[pluginName] ~= nil) then
Plugins[pluginName].Unload = function(self,sender,args)
UnloadPlugin();
Turbine.PluginData.Save( Turbine.DataScope.Character, "Satchel", Data );
end
window:SetWantsUpdates(false);
end
When referencing your Data variable from outside of the class you shoud be doing so via SatchelWindow.Data
Code:
Turbine.PluginData.Save( Turbine.DataScope.Character, "Satchel", SatchelWindow.Data );
or the issue could possibly be here:
Code:
----SAVE CURENT POSITION WHEN MOVED---
self.PositionChanged=function(sender,args)
self.Data.x,self.Data.y=self:GetPosition()
Turbine.PluginData.Save( Turbine.DataScope.Character, "Satchel", self.Data );
You haven't declared data as a table. Not sure if that would make a difference or not (I am fairly new to lua). But you could try:
Code:
----LOAD PRIOR POSITION----
self.Data = Turbine.PluginData.Load( Turbine.DataScope.Character, "SatchelData")
if (self.Data==nil)then
self.Data = { };
self.Data.x = 100;
self.Data.y = 100;
self:SetPosition(100 , 100);
else
self:SetPosition(self.Data.x,self.Data.y)
end
Like I said, im fairly new to LUA so there may be a better place to declare Data as a table. But I am guessing the issue is because when first load it self.Data never gets declared as a table, so you get an error when you try to write to self.Data.x and self.Data.y.