Thread Tools Display Modes
04/19/22, 04:05 PM   #1
Askedal
Join Date: Aug 2017
Posts: 9
Keybinding

Hi,

I'm currently working on an updated version of SmarterAutoLoot and have a problem to get the key binding to work. I have a binding.xml as

Code:
<Bindings>
	<Layer name="SI_KEYBINDINGS_LAYER_GENERAL">
		<Category name="Smarter Autoloot">
			<Action name="SAL_TOOGLE">
				<Down>SmarterAutoLoot:SALToggle</Down>  
			</Action>
		</Category>
	</Layer>
</Bindings>
and a function

Code:
function SmarterAutoLoot:SALToggle()
	self.db.enabled = not self.db.enabled
	self:ToggleAutoLoot()
end
that should be called to swith off the AddOn on the fly. In the key binding setting I see the entry for my AddOn and can assign a key to it. But when I start the game the only thing I get is an UI error

Code:
:1: function arguments expected near '<eof>'
What is wrong with this type of construct, do I oversee something ?

Many thanks

Askedal
  Reply With Quote
04/19/22, 05:24 PM   #2
Baertram
Super Moderator
 
Baertram's Avatar
WoWInterface Super Mod
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 4,963
You need to actually call the function in the keybind. You currently only added the name there, without the () to start it.
That's why it tells you "function arguments expected" as you defined the function to be called, but no arguments/parameters.

Code:
<Down>SmarterAutoLoot:SALToggle</Down>
->

Code:
<Down>SmarterAutoLoot:SALToggle()</Down>
If this does not work try the . notation instead:
Code:
<Down>SmarterAutoLoot.SALToggle(SmarterAutoLoot)</Down>
  Reply With Quote
04/20/22, 03:17 AM   #3
Askedal
Join Date: Aug 2017
Posts: 9
Hi,

many thanks for your suggestions, I tried all of them, but when I pressed the assigned key I get

Code:
:1: function expected instead of nil
|rstack traceback:
:1: in function '(main chunk)'
|caaaaaa<Locals> keybind = "SAL_TOOGLE" </Locals>|r
Any idea how to fix this ?
Many thanks

Askedal
  Reply With Quote
04/20/22, 07:02 AM   #4
Baertram
Super Moderator
 
Baertram's Avatar
WoWInterface Super Mod
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 4,963
Could you please link the COMPLETE addon here, zip file with all files in it, so we can have a look. It's hard to "guess" things.

It looks like your variable SmarterAutoLoot is nil then as the keybind was created OR the function SmarterAutoLoot.SALToggle is nil at the time.
Is the variable SmarterAutoLoot global? or was it defined local SmarterAutoLoot ?
If it's local you cannot use it in the keybind and you need to remove the local up in front.

If it is global either the varibale SmarterAutoLoot was not defined as the bindings.xml file was loaded
so you need to change the load order of the files in your txt file to load the file where the variable SmarterAutoLoot will be created first and then also define the function SmarterAutoLoot.SALToggle in there properly before the keybinding file bindings.xml is loaded.
  Reply With Quote
04/20/22, 04:24 PM   #5
Askedal
Join Date: Aug 2017
Posts: 9
Hi,

currently the SmarterAutoloot variable is a local one, but when I change this I get an error in the SmarterAutoLoot_Startup function. You can find the complete Addon here http://www.hortien.com/upload/SmarterAutoloot.zip.

I haven't written this code, I only try to make it more usable. No other of my addon have this _Startup function, so it seems something unique.

Many thanks
Askedal
  Reply With Quote
04/20/22, 05:20 PM   #6
Baertram
Super Moderator
 
Baertram's Avatar
WoWInterface Super Mod
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 4,963
If a variable is local you cannot use it out of the scope (outside of a surrounding file, a surrounding function, a surrounding if ... end or surrounding for ... do endloop).
If you want to use it in another file you need to define it global, either by using _G[<variableName>] or just <variableName> instead of local <variableName>

After checking the code SmarterAutoLoot is only a local "class" which you can see via local SmarterAutoLoot = ZO_Object:Subclass()
And a class needs to be used to assign to an object via it's :New function, so you need to search for SmarterAutoLoot:New and would find:
_Instance = SmarterAutoLoot:New( self )

So _Instance is the global, cuz there is no local in front of it, variable which points to the SmarterAutoLoot class' object and at the bindings file you'd need to use

Code:
<Bindings>
	<Layer name="SI_KEYBINDINGS_LAYER_GENERAL">
		<Category name="Smarter Autoloot">
			<Action name="SAL_TOOGLE">
				<Down>_Instance:SALToggle()</Down>  
			</Action>
		</Category>
	</Layer>
</Bindings>

As _Instance  is not very unique in the global namespace you should definately rename that in all of the addon files to something more unique like
_SMAInstance
I've renamed it to SMAGlobalObject, you can download the version here for trying, have not tested it yet:
https://www.dropbox.com/s/yd7grb4v3z...bject.zip?dl=1

Last edited by Baertram : 04/20/22 at 05:33 PM.
  Reply With Quote
04/21/22, 05:55 AM   #7
Askedal
Join Date: Aug 2017
Posts: 9
Many thanks, it works like a charm now
Now that I better understand how this key binding works, I might implement others..

If you don't mind, I have another small problem with the Addon: When you loot a container from your inventory, like the one you get for the craft dailies, the empty loot window doesn't close, it stays open until you either move or open the inventory again. It is not possible to close the loot window with either the "take all" option or the "destroy all" button (if enabled). This only happens for containers, I tried several things as adding waiting circles (not a good idea) or run an additonal endloot, but nothing helped.

Many thanks

Askedal
  Reply With Quote
04/21/22, 09:59 AM   #8
Baertram
Super Moderator
 
Baertram's Avatar
WoWInterface Super Mod
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 4,963
Try to call the function EndLooting(), this is what the vanilla game code does.
here is the vanilla code doing this:
https://github.com/esoui/esoui/blob/..._shared.lua#L8

Else try LOOT_SHARED:Hide()
here is the vanilla code doing this:
https://github.com/esoui/esoui/blob/...shared.lua#L48

But important, there is a comment: CloseLootWindow() -- Called when C++ is telling us to close the window. Don't call CloseLoot.
So normally this function will be called from non lua c++code and you shold not fiddle around it.

And the hide function's code:
https://github.com/esoui/esoui/blob/...shared.lua#L77

If you wonder why there always is used ZO_Loot_Shared: and I told you to use LOOT_SHARED:
Same as with the keybind.
ZO_Loot_Shared is the "class" and LOOT_SHARED is the object created via function :New to this class:
https://github.com/esoui/esoui/blob/...hared.lua#L199

Last edited by Baertram : 04/21/22 at 10:01 AM.
  Reply With Quote
04/22/22, 07:53 AM   #9
Askedal
Join Date: Aug 2017
Posts: 9
Unfortunately this doesn't do anything. I have the EndLooting() already in my code and it is called every time.

Code:
num = GetNumLootItems()

	if (num == 0 ) then
		PlayLootSound(0,true)
		EndLooting()
	end

I tried to replace it with LOOT_SHARED:Hide(), even tried calling it multiple times, but the behavior stayed the same. When I tried to put in some wait cycles the other week, sometimes the loot window disappeared for containers, but I couldn't keep the waits in the code, they made it so slow and nearly unusable. Maybe it is a timing problem ? Is there a loot window for containers (e.g. CONTAINER_SHARED ??) that I can close / hide ?

Many thanks for your help
  Reply With Quote
04/22/22, 12:10 PM   #10
Baertram
Super Moderator
 
Baertram's Avatar
WoWInterface Super Mod
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 4,963
Sorry I don't know, never had looked into that.

Try to read the code of Dolgubons Lazy Writ Creator as it got some auto loot or containers,
or other addons that provide that feature.
  Reply With Quote
05/09/22, 04:03 PM   #11
Askedal
Join Date: Aug 2017
Posts: 9
I think I solved it, it was just the scene that stayed open, after switching back to the inventory scene, it works like a charm. Many thanks for you help!
  Reply With Quote

ESOUI » Developer Discussions » Lua/XML Help » Keybinding

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