WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   Lua/XML Help (https://www.wowinterface.com/forums/forumdisplay.php?f=16)
-   -   Create custom event (https://www.wowinterface.com/forums/showthread.php?t=59538)

Benalish 03-23-23 09:20 AM

Create custom event
 
As the title suggests, is it possible to create a custom event that can be used as a script?

Fizzlemizz 03-23-23 10:31 AM

You can't register a custom event but you can
Code:

frame:GetScript("OnEvent")(frame, "my_custom_event", somerarg)

Benalish 03-23-23 12:26 PM

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?

Fizzlemizz 03-23-23 01:38 PM

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.

Benalish 03-23-23 03:05 PM

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

Fizzlemizz 03-23-23 04:40 PM

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.


All times are GMT -6. The time now is 02:16 PM.

vBulletin © 2024, Jelsoft Enterprises Ltd
© 2004 - 2022 MMOUI