lotrointerface.com
Search Downloads


Go Back   LoTROInterface > LotRO > Developer Discussions > Lua Programming Help (L)

Reply
Thread Tools Display Modes
  #1  
Unread 01-08-2016, 04:20 PM
corhub's Avatar
corhub corhub is offline
The Undefeated
Interface Author - Click to view interfaces
 
Join Date: Sep 2010
Posts: 7
Basic Coding Help Needed

Ok, so I went through the first part of Garan's noob post and was able to get Hello World working but now I'm lost I was a programmer but never in C and the coding of lua is not something I am used to. I have been looking at examples of lua scripts but I don't seem to be able to decipher them so that I can write my own. My first attempt at going off on my own was to just use the window to display my characters name and couldn't figure out how to do that. What I really want to do is just read the chat log so that I can extract my quest and deed information to a file that I can then import into Excel. I can code VBA quite well.

If someone could point me to a good example or give me some help here, I would greatly appreciate it.

Thanks in advance!
Reply With Quote
  #2  
Unread 01-08-2016, 11:50 PM
Garan's Avatar
Garan Garan is offline
The Undying
Interface Author - Click to view interfaces
 
Join Date: Oct 2010
Posts: 340
Getting your character's name is pretty easy once you know that there is a slight oddity to the local player - Turbine decided to make it so that we have to explicitly get an instance of the local player by calling the GetInstance() method (it made some of their internal coding easier). So, to get your character's name, the first thing to do is get an instance of your character and then use the GetName() method (don't forget to import Turbine.Gameplay):
Code:
import "Turbine.Gameplay";

localPlayer=Turbine.Gameplay.LocalPlayer.GetInstance();
charName=localPlayer:GetName();
I would suggest working your way through more of the posts on the "Writing LotRO Lua Plugins for Noobs" thread as there are a lot of subjects covered in there that are pretty important, such as proper handling of event handlers to prevent stomping on other plugins' event handlers.

As to examples of handling the chat log, the best way to learn about it is to look at a plugin that accesses the chat log. The Alerter plugin deals quite a bit with the chat log. Another example is the AltViewer plugin but I don't recall which tabs are included in the published version.
Reply With Quote
  #3  
Unread 01-09-2016, 11:46 AM
corhub's Avatar
corhub corhub is offline
The Undefeated
Interface Author - Click to view interfaces
 
Join Date: Sep 2010
Posts: 7
Thank you very much And I have been working through the post and did read the sections on event handlers. I will take a look at the examples you suggested. Again, thanks for your reply
Reply With Quote
  #4  
Unread 01-09-2016, 04:02 PM
corhub's Avatar
corhub corhub is offline
The Undefeated
Interface Author - Click to view interfaces
 
Join Date: Sep 2010
Posts: 7
import "Turbine";
import "Turbine.Gameplay";
import "Turbine.UI"; -- this will expose the label control that we will implement
import "Turbine.UI.Lotro"; -- this will expose the standard window that we will implement
import "HelloWorld.JHubbard.class";


function SaveData()
Turbine.Shell.WriteLine("The current character is ("..tostring(MYCHAR)..")");
local Settings=MYCHAR;
Turbine.Shell.WriteLine("The settings currently is ("..tostring(Settings)..")");
PatchDataSave( Turbine.DataScope.Account, "Test_File", Settings );
end

I must be missing something else because I keep getting an error message when I'm trying to save data. It says that PatchDataSave is a nil value. I'm not sure what I'm doing wrong this time.
Reply With Quote
  #5  
Unread 01-09-2016, 05:34 PM
Garan's Avatar
Garan Garan is offline
The Undying
Interface Author - Click to view interfaces
 
Join Date: Oct 2010
Posts: 340
PatchDataSave is part of the Vindar patch for international characters. Turbine does not properly support international characters so Lua authors have to first encode the values before saving and then decode them when loading. PatchDataSave and PatchDataLoad are wrapper functions that provide the encoding/decoding and then call the built in functions. Since this is a user resolution to a flaw in the system, it has to be defined in each user project - I have a file I put all the Vindar (Vindar was the user name of the original author of the patch) code into called "VindarPatch.lua" which is included in all of my plugins. This is actually covered in the Noobs thread in the "How Vindar Saved the World" post.
Reply With Quote
  #6  
Unread 01-09-2016, 07:57 PM
Thurallor's Avatar
Thurallor Thurallor is offline
The Undying
Interface Author - Click to view interfaces
 
Join Date: May 2013
Posts: 202
Quote:
Originally Posted by corhub
What I really want to do is just read the chat log so that I can extract my quest and deed information to a file that I can then import into Excel.
Far be it from me to discourage a person from learning to write plugins, but I'm not sure it's possible to do what you want to do. Yes, you can see all of the chat window messages; and yes, you can save them into a file (although in a restricted format). But how do you intend to make your quest and deed information appear in the chat window so you can log it?
Reply With Quote
  #7  
Unread 01-10-2016, 12:59 PM
Garan's Avatar
Garan Garan is offline
The Undying
Interface Author - Click to view interfaces
 
Join Date: Oct 2010
Posts: 340
I was hoping he meant to read the advancement messages that grant and complete quests and deeds and track his own record moving forward (basically what AltInventory 1.x used to do and the next version of AltViewer does). Unfortunately, as Thurallor pointed out, quest and deed history is not accessible via Lua, not even via the chat interface.

As to the file format, I have written several external parsers for the .plugindata file format in various languages (VBA was one but alas I deleted that project many, many moons ago) and it's not really all that hard, especially if the table has no subtables, just a series of keyed entries. For a generic solution, it would help if the developer had a fair knowledge of regular expressions and parsing but for a limited scope it's not really necessary.

Actually, this thread has started getting me interested in dusting off AltViewer along with the external web site I was developing to allow users to track and display their alts on line - a project that got started when Turbine cancelled the MyLotro site but fell victim to the dreaded "ToDo-list-bloat".

Last edited by Garan : 01-10-2016 at 01:03 PM.
Reply With Quote
  #8  
Unread 01-12-2016, 06:11 PM
corhub's Avatar
corhub corhub is offline
The Undefeated
Interface Author - Click to view interfaces
 
Join Date: Sep 2010
Posts: 7
I am not trying for any quest history, just a log of what currently happens and is available in the chat log about quests and deeds so I can parse it later and update my spreadsheets. I know I have to update the history manually but thought I could use the chat log going forward to record quests and deeds and other information that is written to the chat log.

I have already parsed information from kiki inventory to track task items and festival drops, so I do know how to parse the files via vba in excel ... not that hard to do if you are familiar with vba.

-------

Thank you for replying to my questions but I have more. I've been looking at Garan's Lotro Alerter and can't figure out how it's writing to the log window and I can't even figure out how it is getting my characters name. It is difficult for me to understand the lua code, I wish there were simpler examples I could look at. The code is very efficient but that in itself makes it difficult for me to understand. For me, there is no logical flow from defining a variable to where it is used, displayed, written to a file. I know that is because I do not yet understand how the lua coding works and am trying very hard to understand it but I feel as if I am making little to no progress. If it is possible, could someone please include a few lines of code that shows how to do the following: read the chat log (standard and quest only) and how to write to a file (I have done this but don't know the difference between that and appending to the file nor do I know how to write an array to a file) and append to it.

Last edited by corhub : 01-12-2016 at 08:32 PM.
Reply With Quote
  #9  
Unread 01-13-2016, 02:31 AM
Thurallor's Avatar
Thurallor Thurallor is offline
The Undying
Interface Author - Click to view interfaces
 
Join Date: May 2013
Posts: 202
Quote:
Originally Posted by corhub
I've been looking at Garan's Lotro Alerter and can't figure out how it's writing to the log window
I assume you mean the chat window. If so, here's how:
import "Turbine";
Turbine.Shell.WriteLine("Hello, world");
Quote:
and I can't even figure out how it is getting my characters name.
import "Turbine.Gameplay";
local player = Turbine.Gameplay.LocalPlayer:GetInstance();
Turbine.Shell.WriteLine("your name is " .. player:GetName());
Quote:
It is difficult for me to understand the lua code, I wish there were simpler examples I could look at. The code is very efficient but that in itself makes it difficult for me to understand. For me, there is no logical flow from defining a variable to where it is used, displayed, written to a file. I know that is because I do not yet understand how the lua coding works and am trying very hard to understand it but I feel as if I am making little to no progress.
Perhaps with your VBA background you're not comfortable with object-oriented programming. A lot of plugin functionality is done by attaching callback functions to events generated by objects. You should read the "Programming with Class" section in Garan's tutorial. (You should really read the whole thing; it's not that long.)

Quote:
If it is possible, could someone please include a few lines of code that shows how to do the following: read the chat log (standard and quest only)
You have to attach a callback function (event handler) to the Chat object:
import "Turbine";
function ChatMessageReceived(chatobject, args)
Turbine.Shell.WriteLine("channel = " .. args.ChatType .. "; message = " .. args.Message);
-- Note: The list of channels is in the Turbine.ChatType enumeration.
end
AddCallback(Turbine.Chat, "Received", ChatMessageReceived);
Quote:
and how to write to a file (I have done this but don't know the difference between that and appending to the file nor do I know how to write an array to a file) and append to it.
You cannot append to a file; you can only overwrite the entire thing. You use the Load() and Save() functions of the Turbine.PluginData object. See Garan's tutorial.
Reply With Quote
Reply


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
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
TitanBar (help needed) Thorondor Released Interfaces (L) 3 01-17-2015 06:54 AM
Help Needed With 'Horsey' Vald Lua Programming Help (L) 9 02-29-2012 01:31 PM
Help needed... MrJackdaw Lua Programming Help (L) 5 12-22-2010 09:56 AM
D3D10GraphicsCore.dll needed Passatuner Chit Chat 2 10-26-2007 03:35 AM


All times are GMT -5. The time now is 03:55 AM.


Our Network
EQInterface | EQ2Interface | Minion | WoWInterface | ESOUI | LoTROInterface | MMOUI | Swtorui