04/03/14, 06:12 PM | #1 |
SavedVars and functions
Still very new to lua so its probably all me lol
I am having some issues dealing with ZO_SavedVars. for example, I constantly receive a stack traceback error on the line for event manager. I believe I have a issue with how I am recalling the values from ZO_SavedVars. So far google has not been friendly to me with this project. I have a tough time telling the lua code apart from apy function events and w/e else there is in code samples I'm referencing from multiple addons. Any help/tips is apreciated Lua Code:
Last edited by tiomun : 04/03/14 at 08:33 PM. Reason: Found the highlight lua option :) |
|
04/03/14, 06:19 PM | #2 |
What is the stack traceback error you are getting ?
That may help highlight where things are going crazy on you. |
|
04/03/14, 08:32 PM | #3 | |
Code:
Checking type on argument callback failed in ScriptEventManagerRegisterForEventLua stack traceback: [C]: in function 'RegisterForEvent' user:/AddOns/mmoui/mmoui.lua:27: in function '(main chunk)' Last edited by tiomun : 04/03/14 at 08:35 PM. Reason: more info |
||
04/03/14, 09:33 PM | #4 | |
I was able to make some progress on this just with trial and error.
Basically I Changed the function names to MMO_xxx() Insread of MMO.xxx(), added local infront of each function, and Removed the RegisterForEvent and added a simple function call to initialize at the end. Lua Code:
This worked well while I had the call to the functions MMO_bag() commented out much like MMO_actionbar() is commented out. MMO_bag() is in a separate file functions.lua at the moment whether it has any code in the function or not it throws this new error
Lua Code:
Theirs something different about lua that I cant wrap my head around. basic to php and most languages give me little trouble. I am definitely missing something with how the functions work, or variable get passed around. lua examples I see online look very little like what is used in these addons.... Last edited by tiomun : 04/03/14 at 09:39 PM. |
||
04/04/14, 01:46 AM | #5 |
Ok, I think I can see where you are going wrong.
If you bear in mind that some information is only accessible after the addon is loaded or the player is activated things will become easier to implement. If you take a look at my gatherer addon you will see that at the top of the file I have some addon variables and at the bottom I have some functions that are using the event system and are called by the event system. You could almost copy those and just adjust for your addon to get it to work. Try something like the following. local addon_name = "..." local addondata = {} local function init_addondata() addondata=zo_savedvars:new(....) end local function player_activated(eventid) --Player is active and most things are available now end local function addon_loaded(eventid, addon) if addon == addon_name then init_addondata() EVENT_MANAGER:RegisterForEvent(addon_name,EVENT_PLAYER_ACTIVATED,player_activated) end end EVENT_MANAGER:RegisterForEvent(addon_name,EVENT_ADDON_LOADED,addon_loaded) Hope that helps. I use this as the base of all my addons. Last edited by Xrystal : 04/04/14 at 02:12 AM. |
|
04/04/14, 07:05 AM | #6 |
That was a big help I do not have any errors showing up any more, and I think I have a bit of a grasp on the functions now... maybe... let me know if any of my commenting or anything looks off.
However, I cant get the slash command to work. haven't gotten past that point yet. having "SLASH_COMMANDS[addonCommand] = addon_slash" in the init function doesn't work anymore, and it wont work if moved to any of the other functions.... Sorry to be such a noob on all this, and thanks again for the help. Lua Code:
Last edited by tiomun : 04/04/14 at 07:08 AM. |
|
04/04/14, 07:17 AM | #7 |
|
Hey,
line 36 your if compares to variables addon: which is the 2. paramater < OK addon_name: i cant find any variable with that name < I Expect you want to use addonName. Cheers |
04/04/14, 08:34 AM | #8 |
I have slash commands in my gatherer addon so feel free to look at it. I have put comments in there as well. When I get home tonight I will extract that part of it for you.
|
|
04/04/14, 11:27 PM | #9 |
Cr4x good eye thanks
So I looked over the gatherer addonon but that didn't help much with the slash command issue. The problem was still with my functions, and the variables being passes between them. After digging around for a few hours online and looking at different tutorials I realised I was assuming there was something different about lua that I didn't know, but its not actually different in any way, all the source code I was looking at was confusing me due to the different styles of coding people have. Xrystal yours was what pointed me towards that fact since it was similar to how I read/write code. more so than others. After I get a grasp of a language I'm usually fine reading it no matter who created it, but starting out it can be difficult. So here is what I have working for me right now. It handles the slash command and the triggering of functions in the functions.lua script I started just fine. functions just output text to the chat as they are executed for now but the text will be replaced with some actual api content soon to learn/test more on main.lua Lua Code:
functions.lua Lua Code:
Thank you both for all the assistance |
|
04/05/14, 05:25 AM | #10 |
Glad it helped and yes, I get somewhat confused when looking at other code myself.
I'll extract a small segment of my slash code and see if that helps you a bit better than my huge block of code I have in the addon. |
|
04/05/14, 05:54 AM | #11 |
This is the first step for slash commands. Either have this line in your initialising function or call the function there. In essence it is saying, watch for /xrga input and process it with the function ProcessSlashCommands.
Lua Code:
option is anything that appears after /xrga. So first we need to extract what is typed afterwards. This extraction code extracts up to 2 phrases from the command line so to speak. For example /xrga alert is one phrase 'alert' which becomes option[1]. /xrga zone kenarthi's roost is treated as two phrases 'zone' as option[1] and 'kenarthi's roost' as option[2]. It next tests to see if it finds no phrases so that #options equate to 0 or you type 'help' it lists the available options on screen. It then processes the options it found and carries out the code to process them. The two examples I have listed shows the 1 phrase option and 2 phrases option in action. /xrga update to generate the harvest data into a simple table for easy access bypassing the account information not needed for the addon to work. /xrga zone [zonename] uses that simplified harvest data to extract the information related to the zone requested, the current zone if none is requested and if somehow it thinks you are not in a zone it will list everything Lua Code:
I hope that helps you figure that part out. |
|
04/05/14, 09:49 AM | #12 |
@tiomun: Please do not use generically named global variables/names for your functions. Make them local if possible, or at least name them better.
|
|
04/05/14, 03:37 PM | #13 |
@Seerah Don't worry. I wouldn't publish anything like that. its just experimentation and learning for the moment.
@Xrystal Thank you I am getting into the more elaborate chat commands as I work with the settings now. |
|
04/10/14, 11:18 PM | #14 |
Thought I'd share my slash function now that I have it working.
When the slash command is entered this checks for a trailing command. The value of the command is then converted to the arrays key name that defines the message to be displayed, It also generates a function name which will be executed if a function by that name exists. To avoid picking up a normal function in the addon, these dynamically triggered functions use a unique nomenclature. RVD_ instead of RV_ in this example. This is just a snipet of the slash command code. not the complete addon script. there are earlier failsafes to prevent the execution of this affecting other addons Lua Code:
It took a bit of playing with, but I am happy with the results. Thank you again for all the help Last edited by tiomun : 04/10/14 at 11:26 PM. |
|
ESOUI » Developer Discussions » Lua/XML Help » SavedVars and functions |
«
Previous Thread
|
Next Thread
»
|
Display Modes |
Linear Mode |
Switch to Hybrid Mode |
Switch to Threaded Mode |
|
|