lotrointerface.com
Search Downloads


Go Back   LoTROInterface > LotRO > Developer Discussions > Lua Programming Help (L)

Reply
Thread Tools Display Modes
  #21  
Unread 12-13-2011, 09:14 AM
Galuhad's Avatar
Galuhad Galuhad is offline
The Undying
Interface Author - Click to view interfaces
 
Join Date: Dec 2010
Location: Norwich, UK
Posts: 24
I wonder if the problem is caused by the plugin manager trying to load all the plugins simultaneously. Has anyone tried using it to load just one plugin? If this is the problem then perhaps use it to auto-load BootStrap and call your plugins from there. Otherwise it may be needed for authors to revise their load methods if the data is clashing with other plugins possibly causing these bugs?
__________________
Galuhad, Guardians of the Light, Evernight (formally of Eldar RIP)
---
Reply With Quote
  #22  
Unread 12-13-2011, 01:20 PM
Cearbhall's Avatar
Cearbhall Cearbhall is offline
The Undefeated
Interface Author - Click to view interfaces
 
Join Date: Sep 2010
Posts: 5
not the best way i'm sure but can get around this until Turbine fixes it

Code:
--create quickslots

local needsItemAddedEvent = false
local function setShortCuts()
	needsItemAddedEvent = false

	for i = 1, 5 do
		if DB.quickslots[i] then
			local qs = window.quickslots[i]

			local sc = Turbine.UI.Lotro.Shortcut(DB.quickslots[i][1], DB.quickslots[i][2])
			local ok = pcall(qs.SetShortcut, qs, sc)
			if not ok then
				needsItemAddedEvent = true
			end
		end
	end

	if not needsItemAddedEvent and ItemAdded then
		Shady.Helper.Event.UnregisterCallback(backpack, 'ItemAdded', ItemAdded)
	end
end

plugin.Load = function()
	setShortCuts()

	if needsItemAddedEvent then
		local player = Turbine.Gameplay.LocalPlayer.GetInstance()
		backpack = player:GetBackpack()
		ItemAdded = Shady.Helper.Event.RegisterCallback(backpack, 'ItemAdded', function(s, args)
			setShortCuts()
		end)
	end
end
downside: quickslot's shortcut gets set everytime ItemAdded event fires
Of course you can check to see if all your quickslots setshortcut without error and unregister the backpack.ItemAdded event

edit: updated it to do just that

Last edited by Cearbhall : 12-13-2011 at 01:37 PM.
Reply With Quote
  #23  
Unread 12-15-2011, 01:18 PM
Stever1388 Stever1388 is offline
The Undying
Interface Author - Click to view interfaces
 
Join Date: Nov 2010
Posts: 33
I think the biggest problem stems from the fact that you can't use Quickslot:SetShortcut() to set an invalid shortcut, whether the shortcut was once valid or not. I'm not really sure how much interest there is in this, since it could be overcome in tons of other ways, depending on author preference and all that, but here is an extension of the Quickslot class stores the Shortcut when you use Quickslot:SetShortcut() separately from the actual Turbine.UI.Lotro.Quickslot:SetShortcut() method, meaning it will save the Shortcut even if the Shortcut is invalid, and will then continue to return that Shortcut when you call GetShortcut(). This should work for everyone without changing any code other than changing quickslot = Turbine.UI.Lotro.Quickslot() code to quickslot = Quickslot() (or where ever they place Quickslot.lua)

This doesn't actually fix the problem, it's up the programmer to then set Backpack ItemAdded event handlers to watch for items being added to the inventory so that the Quickslots can be updated.

This also surrounds the other SetShortcut() method with pcall() to prevent those errors, but returns true/false if the SetShortcut() worked/didn't work so you can still act accordingly.

Code:
-- This class attempts to fix the problem with the Quickslot class that 
-- 	prevents it from storing invalid Shortcuts, even if the Shortcut was once valid.
--	For example, if you have a Health Potion in a Quickslot, and you run out of that potion,
-- 	the next time you load the plugin that Quickslot will be cleared (you can't set a Shortcut if
--	you don't have the item in your bag). At that point GetShortcut() will return an empty Shortcut.
-- 	Using this class, GetShortcut() would still return the Health Potion shortcut.

-- Please note that if you use this class you MUST use the AddCallback function by Pengoros
-- 	for ShortcutChanged, since this class uses that EventHandler to make sure 
-- 	the Shortcut returned by GetShortcut() is the correct one.

-- One other thing, it is up to the programmer to decide how they want to handle invalid shortcuts outside
--	of this class. This class will not update a Quickslot/Shortcut every time the Backpack:ItemAdded event
-- 	is fired, so Quickslots/Shortcuts will not be fixed even if you get the item back into your inventory.
-- 	You will have to reload the plugin to get it to appear again.

import "Turbine.UI.Lotro";

-- Extend normal Turbine Quickslot class
Quickslot = class ( Turbine.UI.Lotro.Quickslot );

-- Constructor
function Quickslot:Constructor()
	Turbine.UI.Lotro.Quickslot.Constructor( self );

	-- self.shortcut stores the Shortcut even if 
	-- 	Turbine.UI.Lotro.Quickslot:SetShortcut(shortcut)
	-- 	would throw an error
	self.shortcut = Turbine.UI.Lotro.Quickslot.GetShortcut( self );

	-- Create an EventHandler that watches for when the Shortcut has changed;
	-- when it has, set self.shortcut to the new Shortcut
	shortcutChangedHandler = function(sender, args)
		self.shortcut = Turbine.UI.Lotro.Quickslot.GetShortcut( self );
	end

	AddCallback( self, "ShortcutChanged", shortcutChangedHandler );
end

-- Sets the Shortcut of the Quickslot by setting self.shortcut to the new Shortcut.

-- To simplify things, this method uses pcall() to set the Shortcut, which
-- 	means you won't get errors when setting Shortcuts.

-- In order to know whether the Shortcut was successfully set though, this method 
-- 	returns true if the Shortcut was set, and false if an error would have been thrown.

-- If you DO NOT want your Shortcuts set to invalid Shortcuts (even though they will never reappear
-- 	on the Quickslot unless the user gets the item back into their inventory and then reloads the plugin), set Shortcuts
--	like this: if(Quickslot.SetShortcut(Shortcut) == false) then Quickslot.SetShortcut(Turbine.UI.Lotro.Shortcut()) end
function Quickslot:SetShortcut(value)
	self.shortcut = value;
	return pcall(function() Turbine.UI.Lotro.Quickslot.SetShortcut( self , value) end);
end

-- This function only returns self.shortcut; However, the only time this will be different than
-- using the old GetShortcut() will be when you use SetShortcut() and SetShortcut() returns false.
function Quickslot:GetShortcut()
	return self.shortcut;
end

-- The amazing Callback function by Pengoros
function AddCallback(object, event, callback)
    if (object[event] == nil) then
        object[event] = callback;
    else
        if (type(object[event]) == "table") then
            table.insert(object[event], callback);
        else
            object[event] = {object[event], callback};
        end
    end
    return callback;
end
If anyone sees anything inherently wrong with this code, let me know, because I'm using it to do some fixes of plugins I use and need to work correctly with the LOTRO Plugin Manager (as I am really lazy and hate having to load plugins each time I log in, even though I use a shortcut key and Bootstray so it takes all of 2 keystrokes to do so). I haven't had any problems with it the last day I've used it, but I can't say I've done a whole bunch of testing.

If there's interest I (or someone else, doesn't really matter) can post this as a file so people can download it and use it. But as I said, not sure there will be much interest, since I'm not the best LUA programmer and there's probably better ways to do this depending on how your plugins are already coded.
Reply With Quote
  #24  
Unread 12-16-2011, 02:24 AM
MrJackdaw's Avatar
MrJackdaw MrJackdaw is offline
The Undying
Interface Author - Click to view interfaces
 
Join Date: Feb 2009
Location: Lancaster, England
Posts: 249
Stever1388 - This works to fix the loading bug! Rolling (with slight modification) into the next Bevy release!

Thank you!
__________________
************************************************** ************************************************** **
"Our ideals may never be realised, But they indicate what we are trying to do." Dick Tahta
Reply With Quote
Reply


Thread Tools
Display Modes

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
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Resurrect the LOTRO-Manager Adder Interface Requests (L) 1 12-03-2011 07:33 AM
bootstrap plugin manager not loading other plugins ccrider Interface Help (L) 6 09-11-2011 05:15 PM
Plugin Manager 0.2 help jingo386 Script & Skin Managers 1 09-20-2010 11:33 PM
Plugin Manager Sirak Script & Skin Managers 8 09-12-2010 04:35 PM
BETA: LotRO-Manager Bl4ckSh33p Dev Tools (L) 2 01-30-2008 07:45 AM


All times are GMT -5. The time now is 04:44 AM.


Our Network
EQInterface | EQ2Interface | Minion | WoWInterface | ESOUI | LoTROInterface | MMOUI | Swtorui