LUA AddOn, OnLoad / Caching / Scripting

UI and Macro
Dear Community,

I fear that I may be in the wrong forums; however, it wasn't obvious to me from the website where this question would go. Thus, if it must be moved, my apologies in advanced.

I'm working on an add-on that uses a "/slash command" to preform a set of operations. I'm not entirely too familiar with how WoW preforms LUA script execution OnLoad compared to In Game; however, when I type the "/slash command" to preform my operation - does the script run each time, real time, in its entirety - or does it preform some caching of objects?

To place this in context, I'm working on an Addon that uses GetContainerNumSlots() API call. My question is about weather or not I will have to worry about "refreshing" my object's variables that uses GetContainerNumSlots() in the event that something changes between when the AddOn first loads to when the AddOn is ran.

An example would be the following:
1. I login; there are 15 slots in my bag. My Initializer Function runs OnLoad, and GetContainerNumSlots() sets 15 in my object's constructor.

2. I buy a [Fishing Pole] - I now have 14 slots in my bag.

3. I run my AddOn using the "/slash command" - is there 15 slots in my bag, or is there 14 slots in bag?

From testing, I feel as though it is the latter, 14 slots in my bag (which is correct), as scripting languages don't need to be "compiled" per say; however, I just want to be absolutely certain.

Thanks again for your time!

-Ódy @b-rock

You want to post this in the UI and Macro forum:

That forum deals with the in-game API.

This forum deals with the out-of-game internet API.
When you say you run your addon using your slash command I interpret that to mean you are asking your addon to do something and give you some information. If this is so, then I would suggest in the code that executes when you run your slash command you ask for how many slots are free at the moment. I would not do this in the OnLoad unless your addon is supposed to show how many are free immediately upon its start without you needing to run your slash command. If your addon needs to display the total all the time without you needing to run your slash command you are going to need to have your addon monitor events that Blizzard sends when specific things happen. In your case you will want to monitor events that are sent when the contents of your bags change, so you can update your free count each time you receive the event.

Basically when you run your slash command all the code associated with your slash command will be run. This will happen each time you run your slash command. Just because it was run before does not mean it will not be run again. However, the code you have in your OnLoad will only be run when the addon is loaded. This will not be run each time you run your slash command.
When you create a /command, you associate a function with that game input (the typing of the command).

That function is run every time the game processes that slash command. However, any associated code is NOT run.

So if you want your /command to know how many slots there are in your bags each time it's run, it should check that inside the function that you stored into SlashCmdList.
Mildly off topic, but GetContainerNumSlots is the maximum number of slots the bag contains, regardless of what it contains.

If you want free space in a bag, use GetContainerNumFreeSlots:
I know it's been awhile, but I wanted to say thank you everyone for your help in all this. It's appreciated, and it helped me get where I needed to be. Thanks.

Join the Conversation

Return to Forum