LoTROInterface

LoTROInterface (https://www.lotrointerface.com/forums/index.php)
-   Lua Programming Help (L) (https://www.lotrointerface.com/forums/forumdisplay.php?f=50)
-   -   Basic Coding Help Needed (https://www.lotrointerface.com/forums/showthread.php?t=3599)

corhub 01-08-2016 04:20 PM

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!

Garan 01-08-2016 11:50 PM

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.

corhub 01-09-2016 11:46 AM

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 :)

corhub 01-09-2016 04:02 PM

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.

Garan 01-09-2016 05:34 PM

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.

Thurallor 01-09-2016 07:57 PM

Quote:

Originally Posted by corhub (Post 11763)
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?

Garan 01-10-2016 12:59 PM

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".

corhub 01-12-2016 06:11 PM

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.

Thurallor 01-13-2016 02:31 AM

Quote:

Originally Posted by corhub (Post 11775)
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.


All times are GMT -5. The time now is 11:53 PM.

vBulletin® - Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
© MMOUI