January 16, 2010

Hacking LUA

Filed under: Thoughts — Tags: — Kevmar @ 11:00 am

You don’t have to know much about LUA to start hacking around in  it.  If you have any experience in another programming language, its easy to get in and muck around with things.  I have played with several languages. C++, Java, C#, VB6, VB.Net, JScript, VBScript, JavaScript, Batch files, Autohotkey, Html, XML, Flash4, ASP, ASPX, PHP, SQL and Assembly.  I’m not listing this to impress anyone or to say I’m an expert at all of those.  But I am good at working with code and making it do what I want it to do even when I am not familiar with it.  Jumping into LUA was easy for me but I did have a few things slow me down.  Here are some things that I discovered about LUA while working on it that was different to me from other languages.  I figured most of this out by looking at other LUA code and with the help of google.

One of the first things I figured out was that .. is the concatination opperator.  It’s common in many languages to use + or & to combine strings together.

print("Items Skipped: "..totalSkipped)

The print command I just used was a little trick I saw another mod use to generate output.  I saw many many people use DEFAULT_CHAT_FRAME:AddMessage and some of my early LUA code does the same.  I expect there are reasons to use one over the other.  But using print statements to help in debugging is great.

Most languages have a NULL or NOTHING type value for objects that have no value or are not initialized.  In LUA its nil.  I found it hard to fight the habit to type null when I needed to type nil.  Checking for nil was something else I had to figure out.  If an object is nil and you try to use it, you generate an error.  I wanted to use != or “is not nil” or neq like other languages.  I found ~= to be the not equal syntax.  Sometimes its the simplest things that slow you down.

if enchantLink ~= nil then
   print(enchantLink)
end

Functions use a simple syntax like I expect but they can return more than one value.  You can use the underscore to ignore values you don’t care about.  Sometime you only one one or two of the return values.  You can place them all in variables, but using the underscore saves on typing.

skillName, _, _, _, altVerb = GetTradeSkillInfo(index)

The most powerfull thing I found was the ability to call public functions in other mods.  I think functions are public by default so most mods are wide open for interaction. 

local itemId = Skillet:GetItemIDFromLink(itemLink) _, _, _, _, altVerb = GetTradeSkillInfo(index)  if LSW.scrollData[itemId] ~= nil and altVerb == 'Enchant' then      -- Ask LSW for the correct scroll      itemId = LSW.scrollData[itemId]["scrollID"] end

In the example I just gave, I take an item link and use a public function of Skillet to pull out the item ID.  That is an easy function to write but it was so quick to just ask skillet.  GetTradeSkillInfo is a built in api call that gets info about a trade skill.  I use it here to get the skill type.  I then check an array in LSW to see if they have it in the scroll conversion list and make sure the type is an enchant.  I then replace the item id I have with the translated one that LSW has if needed.  This was all the code I needed to add to KTQ for enchant scroll support.

With this stuff in mind, go take a look at other mods.  Start with simple mods and just look around.  Some are packed with thousands of lines of complicated code, others have nice clean functions.  One time I was doing something that interacted with the mailbox.  I downloaded every bulk mailing mod on curse to figure it out.  I was hunting for one small feature and I found it easier in some crapy low rated mod than in the full featured highly popular mod.  Fewer features means less code to look at.  People also do stuff in different ways.

One last thing to remember is that wowwiki has a good section on warcraft API calls.  I use that site a lot to figure things out.  You don’t have to start learning LUA by writing a full mod.  Making little changes to other mods is how I got started.

January 14, 2010

Kevmar, Where are you?

Filed under: News — Tags: — Kevmar @ 9:16 am

I used to be just ok at making gold in WOW.  My biggest market would be patch notes.  I would figure out what changes caused market changes and invested like mad.  Sometimes I get burned but more often I would make bank.  This last year something changed.  The general population started doing that too.  They saw the results people like me made early on and everyone shared what they thought dream shards would do.  This did not take that market away, but it made it swing a little more and made it harder to predict.  If everyone invests into something, your payout is smaller.

So I went online looking for other things people did to make gold.  I revisited some sites I looked at before and it indicated that inscription was the new market to be in.  I also discovered the JMTC forums where there were a lot of very helpful people.  I learned as much as I could from them and became an active member helping others and sharing my ideas.  I found myself stalking the forums a little too much.  I probably should have asked to be a moderator.  I developed my inscription method that lead me to write the core logic in KTQ from those forums.  Many people there helped me beta test and refine it.

I was talking about inscription soo much on the forum that I decided to move it to a blog.  On my blog, I didn’t have to wait for someone to respond too.  I could also lay out my story.  My blog grew at a fairly steady rate.  I commented on other blogs and I released a few mods.  KTQ is the most well known that drives most people here.  I did enjoy sharing my ideas and the ways I made gold.  Even my competition told me they liked to read my blog. 

I had a nice solid system in place.  Bulk herbs, large crafting queues, lots of inventory, and tons of posted auctions.  While I was doing that stuff, I could write on my blog and I had a lot to talk about.  Then my system kind of fell apart on me.  I had a lot of issues in real life that needed my attention out of town and shortly after I returned my account had issues for a few days.  My guild was also only doing easy content to make everyone feel good about killing stuff.  It just got me out of my pattern. 

I did keep posting and I did work auctions from time to time.  I did less and less and over the holiday break, I didn’t even log into wow.  So my unofficial break is more official.  Its also hard for me to come up with good warcraft topics while I am not playing it. I am just shifting my focus to other things for a while.  I kind of did the same thing at the end of Buring Crusade.  The content is winding down and I will not miss much if I take a break now.  I expect a full return for the next expansion if not sooner.   You may still see my mid level warlock riding nude in the barrens when my daughter is online.

So what exactly is my focus now? Programming.  So I am still around writting code. I have just started on a few mini 3D games.  I think they will be a lot of fun if I can make them look as good as I see them in my head.  I’ll talk more about it once I get some core features implemented.  So be ready to see more of me in the future.

January 5, 2010

KTQ/Altoholic fix on its way

Filed under: Uncategorized — Kevmar @ 5:43 pm

I see that Thaoky is doing a lot of work on Altoholic.  By depending on his code for KTQ, he saves me a lot of work.  I was able to just ask Altoholic for an item count and it would give it to me.  That was a wonderful feature that made KQT work.  If I had to write the code to track every item every char had in every location and build in account sharing, I would not have made this mod.  So everyone needs to give Thaoky a big thank you.

The downside is that any number of changes in Altoholic can break KTQ.  The author makes his changes, does his testing, and releases a working mod.  He has no idea what code someone else is connecting into.  That’s a risk I took when I wrote this.  The same holds true for all the other mods I depend on.

Back to the problem that broke KTQ.  Altoholic has a function called GetItemCount(ItemID) that I found one day while digging around the source.  It was a public function so I could call it from another mod and did not have to change any source in Altoholic to do so.  Recently the author restructured his code a little bit.  This is a common thing for devs to do.  In the process he moved that function to a location that made it local (or private).  Private functions can only be seen by local code.  That excludes me.

I decided it was worth contacting the author about it.  Try to get him to open it back up again.  When I checked his change log for the upcoming release, its already changed.

r66 | thaoky | 2009-12-28 18:03:24 +0000 (Mon, 28 Dec 2009) | 1 line Changed paths: M /trunk/Tooltip.lua GetItemCount() is now a public method again.

I took a peak at the alpha source and found where he opened it up for other authors.  I don’t know if it was just KTQ users that requested it or if other mods use it too.  Either way, we thank him for it.  You can find it over at curseforge if you are looking to test it out.  Many of you may find this easier than hacking my source.



Powered by WordPress