Variables

Language: JP EN DE FR
New Items
2023-11-19
users online
Forum » Windower » Support » Variables
Variables
 Leviathan.Shosei
Offline
Server: Leviathan
Game: FFXI
user: Shosei
Posts: 6
By Leviathan.Shosei 2016-07-21 07:19:27
Link | Quote | Reply
 
Is it possible to call variables in an addon that you've defined in a gearswap lua?
 Sylph.Braden
Offline
Server: Sylph
Game: FFXI
Posts: 397
By Sylph.Braden 2016-07-21 08:40:24
Link | Quote | Reply
 
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.
 Leviathan.Azander
Offline
Server: Leviathan
Game: FFXI
user: Shosei
Posts: 2
By Leviathan.Azander 2016-07-21 11:36:57
Link | Quote | Reply
 
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.
 Ragnarok.Flippant
Offline
Server: Ragnarok
Game: FFXI
user: Enceladus
Posts: 658
By Ragnarok.Flippant 2016-07-21 17:37:58
Link | Quote | Reply
 
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 )
 Leviathan.Shosei
Offline
Server: Leviathan
Game: FFXI
user: Shosei
Posts: 6
By Leviathan.Shosei 2016-07-21 18:06:37
Link | Quote | Reply
 
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)
 Leviathan.Shosei
Offline
Server: Leviathan
Game: FFXI
user: Shosei
Posts: 6
By Leviathan.Shosei 2016-07-21 18:12:43
Link | Quote | Reply
 
Also, it turns out I have no idea how to use a code tag.
 Ragnarok.Flippant
Offline
Server: Ragnarok
Game: FFXI
user: Enceladus
Posts: 658
By Ragnarok.Flippant 2016-07-21 18:24:04
Link | Quote | Reply
 
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) 
 Leviathan.Shosei
Offline
Server: Leviathan
Game: FFXI
user: Shosei
Posts: 6
By Leviathan.Shosei 2016-07-21 18:29:44
Link | Quote | Reply
 
You're a wizard.

Seriously, huge help. That's exactly the fucntionality I was hoping for. Thank you.
Log in to post.