Friday, May 27, 2011

Back to work! Addons ho!

After a long hiatus, I am back to programming. Oh boy. Lets get crackin. Where were we? Ahh yes, the Holy Add. I have sat down and actually tried to formulate what the hell I'm going to do as far as an Addon. For my first simple addon, I'm going to make a calculator. Wait, did I already writes this? I dunno. It's been so long. Ah well. but yes, I'm going to make a simple calculator, mainly to get myself better familiarized with LUA and just the world of warcraft API in general.

First thing's first, gotta update all my debugging things. Also gonna try this WoWLua addon. Maybe just to do some simple LUA queries and see how it runs.

I then started to do stuff and forgot to write here. Then I recapped it in my own dev diary and completely forgot about all this. but I shall copy paste my rants here now.

---Pasted from Diary ---
Alright, picking up from where i last left off. Which was a while back. Lets go over what i learned. I actually forgot to write in this damn thing. Le sigh.

Thingy i learned number 1. using the wowlua addon is bad ass. i can do all the calls and it interprets the function like a charm. If anyone else is looking to do some addon stuff, you probably want to get this. It's a hell of a lot easier than always doing a /reload to see what will get printed in a stupid ass print(type(thingy))

Numbar 2, Well.. I guess numbar 2 is really just, I'm learning a whole bunch of new things to do in LUA. But it really does help to have thigns written out and create a clear plan of attack. Just blindly going in here and coding random stuff is not the right way to do things. And i know this. I just needed to reaffirm this to myself.

I've modified the addon to do a few new things. I think i posted earlier that I had it say "STOP FUCKING POKING ME" if i typed in /holyadd poke. Well I've kinda taken it tot he next step. I don't know if i've explicitly stated this in any of my past entries, but I am going to develop a simple calculator within world of warcraft. It's going to have a GUI and will function very similarly to the standard calculator programs you have on your operating system. Yes, i know it's unimpressive, but I need something to start with. Rome wasn't built in a day. And neither was Holy's video game collection. That took... at least 2 days. AT LEAST. Anyway. On with the show.

So adding tot he slash commands, I've done some basic logic to now add things. I have a "global" (Technically it's a local) variable called "Acccumulator." What the accumulator does is.... well... It accumulates... What? Fuck you, i'm naming these things. Now then, I can type in "/ha + number" and it will add the number to the accumulator. Hurrah. Yes, i know the syntax is very not good like. It's actually kinda like LISP. OH GOD MAKE ME FORGET ABOUT THAT STUPID FUCKING LANGUAGE. Lisp lovers go away. You have no place in the house of Holy... Nub...

So adding is cool. I can definately port that function into a button for this calculator. I've also made a simple function that concatinates a string to help build a number. Now, i have had a an argument within myself to determine what's the best way of dealing with growing numbers. Consider the following:

METHOD 1: Treat the number like a string. When you click on a button in the calculator, you are basically just appending a new character to a string. This string is only converted to a number when it's ready for processing. What advantages does this have? Well, I dont' have to deal with the validity of the number until function run time. It relies entirely on the lua function "tonumber()" which means less work for me.

METHOD 2: DO MATH. What do I mean by this? Well, basically when you are clicking on a new number in the calculator, what you are doing is multiplying the current value, number being stored for functioning, by 10 and adding the new number. Which is actually pretty easy to do as well. This allows you to do all sorts of mathematical calculations, and you know you will always be dealing with numbers. Which provides better validation of the results.

both methods seem pretty sound to me. However, like the Highlander, THERE CAN ONLY BE ONE. now then, lets look at the dark side of this whole shebang.

Method 1's weakness: Number validation. I will have to do a ton of string functions to attempt to use on what should be numbers. And I have to always validate said numbers to make sure they aren't all fucked up. Example being Negatives and decimal numbers. I would have to keep tabs on if the negative key was pressed. And if it was, I would have to know if I need to add a negative sign, or if I need to remove a negative sign. Decimals would need to be checked if there was a decimal place already inputted or not.

Method 2's weakness: DO MATH. Yes. i'm not exactly the best at math. i can do some logic, but math.. Eh. I write teh programs to do teh math. The primary problem I'm thinking about when doing math is dealing with numbers after the decimal point. A string makes it easy to just concatinate new numbers. Concatinating more numbers after the decimal allows me to get better accuracy and be more robust. But under the current schema, I would have to take decimal numbers into consideration, I can't just Multiply the entire number by 10. I would need to have a special set of calculations for numbers after a decimal value has been input. that would mean tracking how many digits after the decimal place we are at. Depending on which decimal place I'm after, I will need to multiply the number being "concatinated" by the decimal place and add it. Example being creating 1.005 would involve 1 + 0/10 + 0/100 + 0/1000. Now that I'm putting it in terms of that. It might really not be that bad... Hmm. guess I'm going with Method 2.

That being said, I have adding. Now for some subtraction.

Ok, never mind. I did the whole decimal place thing first. What!? It was on my mind since i wrote the whole stupid fucking thing out ok? Jebus. I just realized while creating this, that this is definately not meant for command line use. If I were to do command line, I'd definately use string method. But for a GUI, I have a little more control over the types of input I will be recieving from the user. Anyway. Now on to subtraction.

Oh goddamnit. upon reviewing of my code, I realize that negative numbers will pose an issue with my whole "ADDING" thing. Wait... I'll just deal with negative numbers before I perform the operation. Never mind. Crisis averted.

Subtraction implemented. Wewt. I think I'll do multiplication and division in a while. I think I want to tackle clearing the accumulator. Which shouldn't take too long either.

Sub 1 minute later and I'm done. Gee gee. Time for those multiplication and division.

Another minute goes by, and with my amazing copy pasting skills it is completed. Huh... Well... I think that's all the functionality to it. Maybe an equals function, but that's mainly something I gotta figure out in the GUI.

Speaking of GUI. God fucking damnit. i need to make one. Ok, I'ma be real. I suck at graphic stuff. I'm god fucking aweful terrible at it. I'm serious. I'm that retarded kid that failed at coloring books. This will be my finest hour... Well... Tomorrow will be... Because I'm not going to tackle GUI stuff till later. that will be a whole nother big ball of learning.


Post a Comment