Thursday, April 12, 2012

Simple addon help needed

[:1]Hey all, I am a C# programmer that is new to LUA. I have a simple question or possible request that I'm sure a lot of you can help with.

I am trying to make a simple addon that hardly has a purpose but I just wanted to do it to see how it was done. That would have been fine if I could figure out how LUA works within WoW.

The addon I am trying to make takes what the user says in chat and removes the first letter of each word. If the word is only one letter, it replaces it with a _. The addon itself would be enabled/disabled through a slash command.

I would have no problem doing this in other languages, but when I look at the resources for LUA that are around the internet, everything I try seems to give me an error.

Thanks in advance for any help provided.|||Main principle:

Your main() is actually the code you write that is not inside a function. So everything else is derived from what you do in that space. You can create an object. Have that object subscribe to events (like incoming chat).

Only Frames can subscribe to events, so the technique is usually to create an empty, non-clickable, non-hidden, transparent frame for that.

If you use the Ace-libraries you don't need to be bothered by this, but you'll have a harder time getting your "main()" in order.

You definately have a lot of reading to do. I suggest trying to modify an existing addon first to get comfortable with how things work.|||I have been able to edit the outgoing messages with simple things like adding a string to the beginning or end of the user's input.

The main issue I am having is allowing the output of another function that contains a loop to replace the entirety of the outgoing message. When simply adding something to the message, I get no errors, but when I try and do what I need to do, I get errors saying "Usage:ChatFrameEditBox:SetText". I am using this code to change the outgoing message (taken from wowwiki):


Code:
function MyAddon_ParseText(chatEntry, send)
if (send == 1) then
local text = chatEntry:GetText();
local newText = text;
chatEntry:SetText( newText );
end

I then added another function under this that takes a string as input (text) and loops through it, separating it at the spaces between words, putting them into an array (this might be the problem as I don't know how lua uses arrays). Then I set the newtest variable to that function so 'fSplit(text)'. At this point I get errors in game.



C# code for what I am trying to do:


Code:
string s1 = txtInput.Text;
char[] sep = new char[] { ' ' };
foreach (string s2 in s1.Split(sep))
{
string s3 = s2.Remove(0, 1);
if (s3.Length < 1)
{
txtOutput.Text += "_ ";
}
else
{
txtOutput.Text += s3 + " ";
}
}

Any ideas?|||u should try at WowAce.com too

u might also be interested in string.gsub API and "pattern matching",

i know some lua, but dont know C#, dont really understand much of your code ><

No comments:

Post a Comment