Variables |
||
Variables
Is it possible to call variables in an addon that you've defined in a gearswap lua?
Sylph.Braden
Offline
The short answer is yes. Here's a super basic example:
From GearSwap to Addon: send_command('lua i Addon '..variable) [for a function] or send_command('Addon '..variable) [for a command] From Addon to GearSwap: windower.send_command('gs c '..variable) Would need to know what you're trying to do to go beyond that though. I'm not sure how well I'll be able to explain this, but here goes.
For elemental nukes, I've defined an array called Element_Array with six elements names in it and then have an Element_Index. It simplifies my macro sets pretty significantly when used in conjuction with some keybinds/macros. When I switch elements, a message comes up in chat "Element set to fire." or whatever. A friend wrote a simple addon that reads the chat log for that line of text and then outputs the element on screen, which I have placed up along the top and is always visible when on BLM/GEO/SCH. I've found that I never look at the log when switching elements any more and want to eliminate that add_to_chat. Ideally, the addon would use the Element_Array[Element_Index] value from my lua to output to the screen. Sounds quite possibly like the function of the addon could just be moved to your GS. But otherwise, as Braden said, you would replace the add_to_chat command with a command that passes the value of the variable to the addon each time you change that var in GS.
Code send_command('addon_name_here settext '..Element_Array[Element_Index]) Then pick it up using the addon command event inside the addon. Something like this, depending on how exactly the addon handles updating the text. Code windower.register_event('addon command', function(command, ...) local args = T{...} if command=='settext' then text_content = args:concat(' ') update_text() end end ) I really appreciate the help; I have a very basic understanding of lua building, and the language really binds me up.
The addon is called ES, so i inserted this line into my GS lua: send_command('ES settext '..Element_Array[Element_Index]) Then in the ES addon, I'm struggling with how to structure picking it up. The addon uses a settings file pretty much identical to that of the distance addon, so position, size of text, font, color, can be manipulated. So here's the addon with my changes; any more advice you can give would be greatly appreciated. When I reload the addon, i get the error ES: lua runtime error: attempt to call a string value. config = require('config') texts = require('texts') settings = config.load({}) ES = texts.new(settings) ES:show() windower.register_event('load', function(new) ES:text('Element: Thunder'); ES:show() end) windower.register_event('addon command', function(command,..Element_Array[Element_Index]) local args = T{..Element_Array[Element_Index]} if command == 'settext' then text_content = ES:text('Element: '..Element_Array[Element_Index]); update_text() end end) Also, it turns out I have no idea how to use a code tag.
You're pasting Element_Array[Element_Index] in odd places, it should never be in the addon (that table doesn't exist within the addon).
The '...' represents every unnamed argument passed to the function. args = T{...} creates a table from those series of unnamed values, and args:concat(' ') then converts them into a space-delimited string. Try this Code windower.register_event('addon command', function(command,...) local args = T{...} if command == 'settext' then ES:text('Element: '..args:concat(" ")); end end) |
||
All FFXI content and images © 2002-2024 SQUARE ENIX CO., LTD. FINAL
FANTASY is a registered trademark of Square Enix Co., Ltd.
|