Clickable Button Documentation?

Language: JP EN DE FR
2010-09-08
New Items
users online
Forum » Windower » Support » Clickable button documentation?
Clickable button documentation?
Offline
By LightningHelix 2026-05-04 07:24:13
Link | Quote | Reply
 
Incredibly broad question, but I couldn't think of anywhere better to ask. I'm wondering how exactly people create a clickable button via a lua addon, and whether there's any documentation about it.

Here's what I naively expected to work:
Code
_addon.name = 'testing'
_addon.author = 'me'
_addon.version = '0.0.1'
_addon.commands = {'testing'}

texts = require('texts') --to create the box
require('luau') --to make T{} work, I have no idea how to do box settings without this lol 

--on addon load, create box
windower.register_event('load', function (...)

  generate_text()

end)

--this SHOULD only fire on left click, but...
function left_click_function()
  windower.add_to_chat(216, 'Success!')
end


--generate the box on addon load
function generate_text()

  --define some text
  BOX_CONTENTS = '\\cs(0, 0, 0)' .. 'HELLO! I AM A BOX. ' .. '\\cr\n' .. '\\cr\n'

  --create the box
  ACTUAL_BOX = texts.new(windowSettings) 

  --put the text in the box
  ACTUAL_BOX:text(BOX_CONTENTS)

  --and make it all visible
  ACTUAL_BOX:visible(true)

  --now, I naively expect this to "associate" the event with the box...
  ACTUAL_BOX:register_event('left_click', left_click_function())

end

--settings for the box, you can ignore this
windowSettings = T{}
windowSettings.pos = T{}
windowSettings.pos.x = 400
windowSettings.pos.y = 400
windowSettings.bg = T{}
windowSettings.bg.red = 150
windowSettings.bg.green = 150
windowSettings.bg.blue = 150

Copypaste that, name it testing.lua, run it...
and you'll see that the register_event on line 38 is running immediately on addon load. Straight into the chat log. No clicking required, which is not what I wanted.

1) How do I register an event to trigger on a left click?
2) How do I make sure that the left click is located within a specific box? I'm aware that the left click event has (X, Y) parameters, so I could keep a table tracking the position of each object I create, but again, clearly not the easiest way to do it.

I did do some research, I promise:

Any help would be much appreciated, because I am very stupid. If there's just like, a "here's how you do this for dummies" somewhere I'm missing?
 Fenrir.Jinxs
Offline
Server: Fenrir
Game: FFXI
User: Jinxs
Posts: 1200
By Fenrir.Jinxs 2026-05-04 08:41:09
Link | Quote | Reply
 
Ask in the windower discord
Offline
Posts: 5
By Thaylia 2026-05-04 08:55:36
Link | Quote | Reply
 
Your bug is on line 38.
Code
ACTUAL_BOX:register_event('left_click', left_click_function())


You wrote left_click_function() with parentheses, which calls the function immediately and passes its return value (nil) to register_event. You want to pass the function itself as a reference:
Code
ACTUAL_BOX:register_event('left_click', left_click_function)
[+]
Offline
Posts: 2666
By Felgarr 2026-05-04 09:17:20
Link | Quote | Reply
 
Thaylia said: »
Your bug is on line 38.
Code
ACTUAL_BOX:register_event('left_click', left_click_function())


You wrote left_click_function() with parentheses, which calls the function immediately and passes its return value (nil) to register_event. You want to pass the function itself as a reference:
Code
ACTUAL_BOX:register_event('left_click', left_click_function)

Wow, a competent BRD *and* a coder. Is there anything you can't do? :)
Offline
By LightningHelix 2026-05-04 09:36:05
Link | Quote | Reply
 
Fenrir.Jinxs said: »
Ask in the windower discord
I'm gonna be the person Googling this in five years and I sure hope that whatever answer we arrive at is somewhere Google can find rather than on a chat server with non-indexed search!

If this isn't the appropriate place to post, by all means point me to somewhere better.
Thaylia said: »
Your bug is on line 38.
Code
ACTUAL_BOX:register_event('left_click', left_click_function())


You wrote left_click_function() with parentheses, which calls the function immediately and passes its return value (nil) to register_event. You want to pass the function itself as a reference:
Code
ACTUAL_BOX:register_event('left_click', left_click_function)
...okay! (I learned several things in the process of reading this short post. Thank you!)

I did that, it no longer runs on load, but when I click on the box it does nothing.

Didn't get an error (like "event left click not available for text objects", which I can create at will by messing up parts of my code"), just a silent failure.

My current code:
[+]
Log in to post.