Create and move frame using LUA only
Oops, put this in the wrong section. A mod please move it.
Im trying to make a frame using lua only but my SetScript functions isn't working. I've tried numerous ways found on wowwiki, these forums and even googleing. I must have missed something important that you have to do in order to make it work. This is my current test code: Code:
function Benque_OnEvent(self, event) What have i missed? |
"OnMouseUp" and "OnMouseDown" arn't events their handlers and should be used as follows.
Code:
local function onmousedownfunc(self, button) |
Quote:
Code:
local function Benque_OnMouseDown(self, button) gah! |
This is wrong:
Code:
frame:SetScript("OnEvent", Benque_OnEvent(frame, ...) ); Code:
frame:SetScript("OnEvent", Benque_OnEvent); |
Quote:
|
Quote:
Note that no two Lua scripts are ever running at the same time. While other threads might be running, the entire UI runs in one thread. This is why performance is so critical to framerate. Similarly, you should not have had a problem even concurrency existed in the UI, because you should NOT be using the global variables. You should be using locals: Code:
-- Don't do this: -- Shirik |
Quote:
Code:
local function Benque_OnMouseDown(button) |
Quote:
|
Quote:
|
Quote:
This is wrong: Code:
function myHandler(arg1) Code:
function myHandler(arg1) Code:
function myHandler(self, event, arg1, arg2, arg3) Code:
function myHandler(self, event, ...) Code:
function myHandler(arg1) Code:
function myHandler(arg1) Regards, -- Shirik |
A very good explanation Shirik, I don't use Setscript that much so I was under the impression that args are actually passed when the event occurs.
I very much rather handle script methods in xml files. I was always wondering if there is any significant difference when you pass arguments there. I'm guessing that there is since method registration is using a different mechanism perhaps ? |
Thanks for your answer to my question, Shirik, it was very clear. I had guesses about the fact that the UI was run in a single thread, but I had difficulties thinking of a test that would make it totally sure :) And yes, obviously, using several calls to the same global variable is bad: when I talked about using a global variable as a parameter, I just meant using its value, but store it wherever you want (the stack being the valid answer, I guess).
Thank you again. |
Yay, i got it to work now!
In order for it to work i had to create a Button, not a frame. I guess frames aren't clickable? Because Frames don't have the function RegisterForClicks(). Code:
local function Benque_OnMouseDown(self, button) |
Quote:
<frame>:SetMovable(true) <frame>:EnableMouse(true) <frame>:RegisterForDrag("LeftButton") as well. |
All times are GMT -6. The time now is 06:56 PM. |
vBulletin © 2024, Jelsoft Enterprises Ltd
© 2004 - 2022 MMOUI