-
Posted by leurk on Sun, 18 Aug 2013 15:05:19
Hi, I want to thank the author of this book who led me to learn a scripting language.
I have a question about the scripts applied to a Frame Object, I tried to handle an "OnEnter" script on the Default ChatFrame for example by outputing a simple message with "print()" like this:
getglobal("ChatFrame1"):SetScript("OnEnter", function () print("Hello World!") end)
it's doesn't work even for an simple Frame created with
CreateFrame()
but when i create it by using XML and setting the scripts tag 'OnEnter' it worked nicely. So what's the probleme with Lua here ?. -
Posted by stolenlegacy on Sun, 18 Aug 2013 17:19:27
Are you getting any Lua errors? Also, how are you trying to run your code (.lua, /run, other)?
Also, is getglobal() defined by the WoW environment? I'm not aware of such a function in baseline Lua.
-
Posted by leurk on Sun, 18 Aug 2013 17:32:16
I've got no errors, i'm runnig with a .lua file and i've also tried with the global table _G[] But no results
-
Posted by stolenlegacy on Sun, 18 Aug 2013 21:16:35
Could you paste your .lua and .toc, as well as providing both file names? I believe that you're running into an issue with the file not being loaded here.
Also, I honestly wouldn't
:SetScript
on a frame you didn't create yourself unless your intention is to override default behavior. Consider using:HookScript
with the same arguments instead. -
Posted by leurk on Sun, 18 Aug 2013 23:50:59
Consider using
:HookScript
with the same arguments instead.I've also tried with this anyway ! here is my simple files:
-toc
## interface: 50300 ## title: Test ## notes: Test ## defaultstate: disabled Test.lua
-lua
_G["ChatFrame1"]:HookScript("OnEnter", function () print("Hello world!") end)
-
Posted by stolenlegacy on Mon, 19 Aug 2013 09:49:51
- Did you enable the addon? You have
DefaultState: disabled
set. - How is your addon's folder named? How are the .toc and the .lua named?
- Did you enable the addon? You have
-
Posted by leurk on Mon, 19 Aug 2013 11:17:33
My addon folder structur are fine, and obviously i checked it before starting to play.
-
Posted by stolenlegacy on Tue, 20 Aug 2013 11:31:42
So if you add something like
print("Test message!")
to the .lua file, it will be printed? -
Posted by leurk on Tue, 20 Aug 2013 11:58:18
Yes any other code works
-
Posted by stolenlegacy on Tue, 20 Aug 2013 15:50:05
It's possible that frames need to have mouse enabled for OnEnter/OnLeave to fire. That might be it.
-
Posted by leurk on Tue, 20 Aug 2013 22:13:18
Yeah You're right a frame need to be mouse enabled to respond mouse events, so far i found the XML atribute enableMouse must be set to true to handle scripts.
thx for your help !
-
Posted by stolenlegacy on Wed, 21 Aug 2013 15:23:53
You can simply call
:EnableMouse(true)
too.