Thursday, April 19, 2012

Mousewheel widget?

Been looking for it on wowwiki, but all I can find is registry for clicks. Looked at Smartbuff, but don't see it in there. So the question is, how do I get a mod to work off of the mousewheel?

In a nutshell, I'm looking for it to allow the user to hold SHIFT and scroll up/down to do some thing.|||frame:EnableMouseWheel(true)

frame:IsMouseWheelEnabled()

frame:SetScript("OnMouseWheel", YourScrollFunc)

Where the arg1 passed to YourScrollFunc is negative for scrolling down I think...|||Awesome, I'll test it out, thx.|||Ok, I still suck at .lua frames. Need some help:

.lua


Code:
-- ONLOAD
function FastTrack_OnLoad()
local f = CreateFrame("Frame","FastTrack_Frame",UIParent)
f:EnableMouseWheel(true)
f:IsMouseWheelEnabled()
f:SetScript("OnMouseWheel", FastTrack_Scroll())
end;

function FastTrack_Scroll()
if IsShiftKeyDown() then
curTrack = curTrack + 1;
SetTracking(curTrack);
end
end

Error:


Code:
Error occured in: Global
Count: 1
Message: ..\AddOns\FastTrack\fasttrack.lua line 12:
Usage: FastTrack_Frame:SetScript("type", function)
Debug:
[C]: ?
[C]: SetScript()
FastTrack\fasttrack.lua:12: FastTrack_OnLoad()
[string "*:OnLoad"]:1:
[string "*:OnLoad"]:1

I'm sure I've gone and screwed things up pretty well on this, but I'm new to creating frames through .lua.

Edit: well, LACK of creating frame in this case..... just need it to run the damned script lol|||k,

I don't think you actually need the :

f:IsMouseWheelEnabled()

It shouldn't be causing any errors; In fact its not really doing anything at all.

I just mentioned it because its available as a way for you to test whether a frame is registered for detecting mouse wheel movement.

So you could :

local isItWheely = f:IsMouseWheelEnabled()

if ( isItWheely ) then print("Wheeeeeeeeeeeeeee!"); end





Your error is happening because of the brackets you have included in :

f:SetScript( "OnMouseWheel", FastTrack_Scroll() )

this should be :

f:SetScript( "OnMouseWheel", FastTrack_Scroll )



Function names can be considered variables like any other, and that is what SetScript is expecting.

For example, after your code above you could declare :

local alternativeFunctionName = FastTrack_Scroll;

and then you could execute :

alternativeFunctionName();

and this will call the same function as if you had called :

FastTrack_Scroll();

So they are both of Type 'function'

i.e. type(alternativeFunctionName) == "function"



SetScript expects either a function name, or a FULL function definition; So you could recode the above to be like this :


Code:

-- ONLOAD
function FastTrack_OnLoad()
local f = CreateFrame("Frame","FastTrack_Frame",UIParent)
f:EnableMouseWheel(true)
f:SetScript("OnMouseWheel", function()
if IsShiftKeyDown() then
curTrack = curTrack + 1;
SetTracking(curTrack);
end
)
end;
|||Ok, so I had a thought and tried to make this easier for myself by just adding a script to the WorldFrame, but I've run into an interesting issue:


Code:
function FastTrack_OnLoad()
local f = WorldFrame
f:EnableMouseWheel(true)
f:SetScript("OnMouseWheel", function()
if IsAltKeyDown() then
curTrack = curTrack + 1;
SetTracking(curTrack);
end
)
end;

Now I get:


Code:
Error occured in: Global
Count: 1
Message: ..\AddOns\FastTrack\fasttrack.lua line 16:
unexpected symbol near ')'
Debug:
[C]: ?

If I take out the ")", I get:

Error occured in: Global

Count: 1

Message: ..\AddOns\FastTrack\fasttrack.lua line 17:

')' expected (to close '(' at line 11) near ';'

Debug:

[C]: ?

[/code]

Ugg. All this so I don't have to make a pointless .xml file. :D|||Sorry, that was kind of my fault for writing code off the top of my head... the function definition is just missing an 'end' statement.

Reformatting it to look a bit more like a standard function definition makes it more obvious...


Code:

f:SetScript("OnMouseWheel",
function()
if IsAltKeyDown() then
curTrack = curTrack + 1;
SetTracking(curTrack);
end
end -- this was missing...
)
|||Sigh, and still nothing happens. Gonna have to find a different way to do it. Thx Telic. :D

Edit: and don't worry, I obviously missed the missing "end" as well|||@ChaosInc

Mmm, well you mentioned you are trying to do things this way in order to do without an .xml file....

Which means OnLoad scripts won't really work (unless you are creating a frame based on a Template that refers to an OnLoad function) ...

Perhaps you actually do have an XML file that defines when the "FastTrack_OnLoad()" function should execute ? Which would seem a bit strange as you are just shifting the need for the XML down one level of abstraction - if you know what I mean

If you don't have an XML file, then just execute your frame creation and SetScripts outside of any function :




Code:

local function FastTrack_Scroll()
if IsShiftKeyDown() then
curTrack = curTrack + 1;
SetTracking(curTrack);
end
end

local f = CreateFrame("Frame","FastTrack_Frame",UIParent)
f:EnableMouseWheel(true)
f:SetScript("OnMouseWheel", FastTrack_Scroll)



If using the WorldFrame, then it won't receive OnMouseWheel notification if your mouse is over the chat frame, or some other frame...

Did the camera stop zooming when you tried to change the WorldFrame's OnMouseWheel script ?

I'd stick to using my own frame, and make sure the mouse is over it when moving the wheel.|||Thx, mate, but project is already finished and released (Fast Track). Between you and Moon, it was made with keybindings instead of simply universal scrolling or anything of the like which did, in fact, break mouse zooming.

Now it's all simple like and works pretty well, save for compensating for Hunter's tracking CDs, which will be fixed when I get a moment to actually do it.

Thanks a bunch mate!

No comments:

Post a Comment