Lua Beginner has some questions
Hello,
I just started messing around with creating lua lotro plugins and i have quite a lot of questions. Please feel free to answer just a couple instead of all if you don't know all answers or you don't feel like it. I've just started and i don't have a lot of experience with programming and have a lot of questions. I'll start with the questions most important to me. 1. Is there a way to disable the tooltip that pops up when you hover over a alias shortcut. the "alias: bla bla bla" popup? 2. When i make a quickslot and bind an alias shortcut to it, can i somehow make it do something extra when you click it? like do the alias shortcut and perform commands. If i try to catch the mouseclick event it does not seem to be willing to do both. At the moment i'm using a workaround by catching the message it sends in the chat and then run the commands from that but it is too slow for what i want to use it for and also not very elegant. 3. When i create a quickslot and drag an item to it ingame and then try to unload the plugin my client crashes 100% of the time. Is this because i do not handle the unloading properly? i've read the "writing plugins for noobs" post from garan on lotro forums (https://www.lotro.com/forums/showthr...gins-for-Noobs) but i didn't really understand the part about unloading right. How should i write the unload section for my plugin? 4. What is the max size image i can load? I was trying to make an animation by making 2 Turbine.UI.Control() things, then making control 1 parent of control 2 and setting a size for control 1 and then setting a image with the whole animation (like 10 frames) as background for control 2 and then moving control 2's relative position to control 1 so it gets cropped. When trying this it worked for really small images but it didn't when my images were larger then around 50x50 pixels. Would you advice me to not use animations or load 10 different pictures? 5. Then finally i have a couple of questions about what i saw in this thread: http://www.lotrointerface.com/forums...ead.php?t=1866 Here in the 2nd post Garan gives tips on hiding quickslots. Garan says you should make your quickslot 34 pixels higher and wider and then crop it by making another control with a smaller size the parent to hide the alias text. But in the example code Garan also makes a black window in front of the quickslot to hide the icon boundry when you hover. But why make the extra control and crop the quickslot? the black window hides the text as well right? Or let me ask it like this: What extra functionality do you get making your quickslot part of a different control like this? Also Garan says you should write code to prevent people from dragging your shortcut out of the quickslot, but somehow for me this behavior is default? i cannot drag the shortcut out of there even if i wanted to. Did an update change these things or do i miss the point of these things altogether? Thanks in advance. |
Hello,
I'll try answering your questions in order: Quote:
Quote:
Quote:
Quote:
Quote:
As to dragging the shortcut out of the quickslot, I believe it is still possible to accidentally drag a shortcut out of a quickslot if it is not prevented by the author. Are you possibly playing with a Mac or Linux install? That may make a difference to the shortcut drag behavior. |
Thank you so much for the quick response and answers to my questions!
For the answers: 1. Quote:
2. Quote:
3. Quote:
Code:
DisplaySize = {Turbine.UI.Display:GetWidth(),Turbine.UI.Display:GetHeight()}; It's not much of a problem as i would uncomment "MainWindow.Button[1]:SetAllowDrop(false);" if i would use it as a button, and i wouldn't try to hide it if i used it as a quickslot i want to drag stuff to. 4. Quote:
Code:
MainWindow.AniCrop = Turbine.UI.Control(); But what i meant with my question before regarding unloading was how do i unload this properly? i think i need 2 things here: "RemoveCallback(MainWindow, "Update", Winup);" and "MainWindow:SetWantsUpdates(false);". But where do i put them? Maybe like this? Code:
unload = function(sender,args) I'm very confused sorry :confused: 5. Quote:
Quote:
Thanks again for helping me understand LUA and Turbines API a lot better! |
Hi,
The first thing I noticed in your code is that you are using SetParent on Window controls. Windows are top level objects and should never be used as child controls for two reasons. First, you should always use the object class that provides the needed functionality with the minimum of overhead - since all you are looking for is a container, a simple Control object is the best choice, Windows have a ton of additional functionality and thus overhead and will cause your plugin to run less efficiently. Second, some classes may include function definitions that were never meant to actually be implemented and implementing those functions can sometimes cause unreliable functionality - the SetParent function of the Window class is such a function (since Windows are top level and inherently parentless). Additionally, I noticed that your ButtonHider is a child of the Quickslot - this is backwards, the quickslot should be a child of the container that is used to clip it. I don't know if assigning a child control to a quickslot could cause a crash as I've never tried it (but I probably will now, just out of curiosity). Your crash is probably a combination of assigning a child to a control that was never intended as a container AND that child being a window object. The Unload handler does not have to be treated like an event handler in that it is not a shared function (no need for AddCallback). Theoretically you could use AddCallback if you wanted a table of Unload handlers (I can think of at least one use for this) but it is not necessary. There are two ways to assign the Unload handler due to a quirk in the way Lua works. When plugins were first implemented, there was no way for a plugin to reference itself while its code was being parsed and loaded so authors took to using an Update event to assign the Unload handler using the Plugins collection in the first Update event after the plugin started actually running. Turbine has since created the "plugin" object (notice the all lowercase name) which is a temporary reference to the instance of the plugin that is only valid while the plugin is loading so you can now assign your Unload handler by referencing your plugin as "plugin". Ex: Code:
plugin.Unload=function() Most of my plugins use the Plugins collection and Update handler method just because most of my plugins were created prior to Turbine developing the "plugin" reference (and I'm just too lazy to go back and change all of them). Another minor point, I noticed you created and use your shortcut as: Code:
Shortcut = Turbine.UI.Lotro.Shortcut( Turbine.UI.Lotro.ShortcutType.Alias, "/w Hamkaas hoifcdfgdsfgdsfgsdfgsdfgsdfgsdfgsdfgdfsgsdfgsdfgsdfgsdfgsdfgsdf"); Code:
MainWindow.Button[1]:SetShortcut(Turbine.UI.Lotro.Shortcut( Turbine.UI.Lotro.ShortcutType.Alias, "/w Hamkaas hoifcdfgdsfgdsfgsdfgsdfgsdfgsdfgsdfgdfsgsdfgsdfgsdfgsdfgsdfgsdf")); |
Quote:
But I just do it the obvious way, which makes me think I am misunderstanding the question. Example: Code:
import "Turbine.UI.Lotro"; |
Quote:
Quote:
Quote:
Quote:
P.S. did you edit this in since when i had less time when i first read your post i did not read this :p But now i'm trying to use more Local variables and such i was wondering what is the proper way of using them within a function or something? for example: Code:
function DirFlip(DirX,DirY,number,player) Quote:
Thank you guys so much! I'm really learning a lot from this. Next time i ask questions i really should try to make myself more clear and also add more of my own code to show what i tried. It was late at night when i wrote this so i guess looking back my post does seem a bit unclear. |
I would recommend reading up on variable scoping. A simple tutorial specific to Lua can be found at:
http://lua-users.org/wiki/ScopeTutorial iirc that tutorial does leave out one important thing, iterators are always local, for instance, in the line "for k,v in pairs(test) do" the variables k and v are automatically local to their iterative loop (you don't need to explicitly create them as local variables first). |
All times are GMT -5. The time now is 10:53 PM. |
vBulletin® - Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
© MMOUI