Thread Tools Display Modes
03-23-23, 09:20 AM   #1
Benalish
A Flamescale Wyrmkin
 
Benalish's Avatar
Join Date: Dec 2012
Posts: 122
Create custom event

As the title suggests, is it possible to create a custom event that can be used as a script?
  Reply With Quote
03-23-23, 10:31 AM   #2
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,871
You can't register a custom event but you can
Code:
frame:GetScript("OnEvent")(frame, "my_custom_event", somerarg)
__________________
Fizzlemizz
Maintainer of Discord Unit Frames and Discord Art.
Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus.
  Reply With Quote
03-23-23, 12:26 PM   #3
Benalish
A Flamescale Wyrmkin
 
Benalish's Avatar
Join Date: Dec 2012
Posts: 122
Ok, I can save a function like this

Lua Code:
  1. local func = frame:GetScript("OnEvent")(frame, "my_custom_event", somerarg)

Then how can I use the function? Via func() of course, but where and how?
  Reply With Quote
03-23-23, 01:38 PM   #4
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,871
So, not an event but a frame method (function)
Lua Code:
  1. function frame:SomeFunc(arg1, arg2)
  2.     self:SetAlpha(arg1)
  3.     if arg2 == "something" then
  4.         -- do other stuff
  5.     end
  6. end

Code:
frame:SomeFunc(0.5, "something")
You can also use a Mixin to apply methods but that ends up being the same thing.
__________________
Fizzlemizz
Maintainer of Discord Unit Frames and Discord Art.
Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus.
  Reply With Quote
03-23-23, 03:05 PM   #5
Benalish
A Flamescale Wyrmkin
 
Benalish's Avatar
Join Date: Dec 2012
Posts: 122
I've created a fairly elaborate frame in XML, which inherits a template. Since writing

Code:
<OnLoad>
    -do stuffs
</OnLoad>
override the template's OnLoad scripts, I was wondering if it was possible to create a custom event.
There is a solution: rewrite the frame code in Lua, but that would be quite cumbersome. Some time ago I read about a little program that converts XML to Lua: does it still exist?

Otherwise, what solutions do you recommend?

In order to avod wall text, this is my frame coded in XML: https://tinyurl.com/ytmwmbt4, from line 52 to line 72

Last edited by Benalish : 03-23-23 at 03:08 PM.
  Reply With Quote
03-23-23, 04:40 PM   #6
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,871
Lua Code:
  1. <OnLoad inherit="prepend">
  2.     -- do stuffs
  3. </OnLoad>

Will allow the template's OnLoad to run. There's also inherit="append" if processing order is critical.
__________________
Fizzlemizz
Maintainer of Discord Unit Frames and Discord Art.
Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus.
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Create custom event

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