Quantcast
Download
(42 Kb)
Download
Updated: 10/22/18 12:00 PM
Pictures
File Info
Compatibility:
Murkmire (4.2)
Updated:10/22/18 12:00 PM
Created:08/13/14 02:42 PM
Monthly downloads:160
Total downloads:3,708
Favorites:12
MD5:
Categories:Chat Mods, Auction House & Vendors, TradeSkill Mods, Miscellaneous, Utility Mods
4.2
Calculator
Version: 3.3.5
by: zeroIndex [More]
--------- Calculator -----------


The text used in the Chat section of the calculator can handle non standard and standard symbols to achieve your goal: Addition: 'a' or '+', Subtraction: 's' or '-', Multiplication: 'm', 'x', or '*', and Division: 'd' or '/'. I added the extra symbols because its much easier to type m or a than search for the proper symbol.

This calculator uses the chat box with the command /calc.
An example: /calc 1+10-4/2*6
You can also use parenthesis for deeper calculations: /calc (12-3)(4/2)
An example of easy symbol input: /calc 1a2m3d2s1

There is also a UI for those of you who would prefer to click for your results

You can set a keybind to allow for a quick open/close of the calculator UI or you can use:
/calc open
/calc close
(note the space between).

There are some options to customize the colors of the calculator to better fit your eyeballs.
There is an option to add the answer from the UI to the chat box. In case you want to look back over your previous numbers.
There is an option to add the answer to all chat tabs so you do not have to limit yourself to staying on the first tab in order to see your answer.
These options are turned on by default.

Please see the attached pictures as they show examples of how the calculator works and what it looks like.


I was tired of tabbing out or looking for my phone when I had to use a calculator so I put this addon together. If you are a seller or if you like to crunch numbers for builds this addon will save you some grief and time. Check it out and feel free to ask if you have any questions, any feed back will be appreciated.

For those of you who have the old version. There is no longer a need to worry about putting spaces in the chat box between numbers and operators. You can leave out spaces or add as many spaces as you want, it does not matter anymore.


--------Thanks/Credit----------
A huge thanks to coolmodi for pointing out how I could simplify things and make the Calculator more robust.
Thanks to Circonian for the awesome tutorials on the wiki.
Thanks to instant for the insAddonTests.
--Version 3.3.5--
Updated the API info

--Version 3.3.4--
Updated the API info
Removed an extra space in the name causing the addon to appear out of order in the list of addons

--Version 3.3.3 --
Updated the API info


--Version 3.3.2--
Updated the API info


--Version 3.3.1--
Updated the API info


--Version 3.3--
Removed functions from global land
Limited the number of decimals to two, no more .33333333333


--Version 3.2--
The lazy options for the chat box input are back.
You can now type 'a' instead of '+'
and 'm' or 'x' instead of '*'
and 'd' instead of '/'
and 's' instead of '-'

Options were added to be able to send the answer from the UI input into the chat tab in case you want to look back over previous numbers.
Optional Files (0)


Post A Reply Comment Options
Unread 07/04/18, 07:03 PM  
zeroIndex
AddOn Author - Click to view AddOns

Forum posts: 1
File comments: 11
Uploads: 2
Re: Needed

Originally Posted by kindredspirit
I love this addon! I use it all the time buying and selling in-game. It seems to work well even though it hasn't had a update in a long time. I just wanted to tell you that its a great addon
Thank you, I really appreciate the comment.
Report comment to moderator  
Reply With Quote
Unread 06/02/18, 09:27 AM  
kindredspirit

Forum posts: 2
File comments: 29
Uploads: 0
Needed

I love this addon! I use it all the time buying and selling in-game. It seems to work well even though it hasn't had a update in a long time. I just wanted to tell you that its a great addon
Report comment to moderator  
Reply With Quote
Unread 01/21/16, 01:44 PM  
zeroIndex
AddOn Author - Click to view AddOns

Forum posts: 1
File comments: 11
Uploads: 2
Originally Posted by coolmodi
The easiest solution I can think of is adding every input to a string and then using LoadString(string) (not sure if the L also was uppercase) to turn it into a function so it can be solved like if you would just write it in LUA code:

Lua Code:
  1. local inputString = ""
  2.  
  3. local function OnInput(input) --every button press except "=" has this as handler
  4.    inputString = inputString...input
  5.    InsertUiUpdateFunctionHere() --so it also shows up in the UI
  6. end
  7.  
  8. local function GetSolution()
  9.    local f = LoadString("return " ... inputString)
  10.    return f()
  11. end
This works like a dream. Thank you for bringing this up.

Originally Posted by coolmodi
Everything that is not local will be in the global namepsace, and if you happen to use a function name that already exists they would overwrite themself.
I have some understanding of this and that's the main reason I gave my functions long names starting with Calc. Ill work on making the functions a bit more neat and local in the future.

Originally Posted by coolmodi
Edit: And if you do this to learn/train programming, then making a parser yourself is a good idea. I also made my addons to learn a bit, and it really helps. It's just LUA, but it still helps with "thinking in code". I know what you mean with "handling the order and depth", I wouldn't have know a few months ago, but now I already can think of how it could work. So if you want to learn something then the loadString() way may be to easy
I have built a parse tree once before and I remember losing a lot of sleep over it. That was with a language I "know" a bit more about. I also had a debugger, not just the in-game errors with ESO.

The loadstring() is almost to easy. But I feel that I have a good understanding of what its doing so I don't feel cheapened by using it . However, it does blow my mind how simple this made everything.
I feel I can also use this to enhance the chat box input, but that will be for another time. School and work are keeping me busy atm.

I value your feedback and will be uploading the new version shortly. Thanks again.
Last edited by zeroIndex : 01/23/16 at 11:40 PM.
Report comment to moderator  
Reply With Quote
Unread 01/21/16, 08:32 AM  
coolmodi
AddOn Author - Click to view AddOns

Forum posts: 47
File comments: 56
Uploads: 3
Originally Posted by zeroIndex
I would like to have that kind of functionality but I find myself running into issues when trying to handle order of operations. My mind quickly starts thinking parse trees and runs away. Maybe I'm overthinking what I would have to do but I currently cannot think of a simple way of going about handling the order and depth.
The easiest solution I can think of is adding every input to a string and then using LoadString(string) (not sure if the L also was uppercase) to turn it into a function so it can be solved like if you would just write it in LUA code:

Lua Code:
  1. local inputString = ""
  2.  
  3. local function OnInput(input) --every button press except "=" has this as handler
  4.    inputString = inputString...input
  5.    InsertUiUpdateFunctionHere() --so it also shows up in the UI
  6. end
  7.  
  8. local function GetSolution()
  9.    local f = LoadString("return " ... inputString)
  10.    return f()
  11. end

What LoadString does is just turning a string into a fucntion, e.g. if inputString would be (4-3)*2, then f would behave like you wrote a function:

Lua Code:
  1. local function f()
  2.    return (4-3)*2
  3. end

and so GetSolution() would return the current solution of inputString as long as it has correct syntax.

Edit: You should also start setting your your functions either local, or adding them to the namespace of your addon by adding it in front like Calc.FunctionName() or Calc:FunctionName().

Using : means the function will get what is in front of the : as the argument "self", you can then use that as you would use Calc within the funtion. Not that useful with just Calc, but it can get handy.

Everything that is not local will be in the global namepsace, and if you happen to use a function name that already exists they would overwrite themself.

Edit: And if you do this to learn/train programming, then making a parser yourself is a good idea. I also made my addons to learn a bit, and it really helps. It's just LUA, but it still helps with "thinking in code". I know what you mean with "handling the order and depth", I wouldn't have know a few months ago, but now I already can think of how it could work. So if you want to learn something then the loadString() way may be to easy
Last edited by coolmodi : 01/21/16 at 08:50 AM.
Report comment to moderator  
Reply With Quote
Unread 01/20/16, 06:56 PM  
zeroIndex
AddOn Author - Click to view AddOns

Forum posts: 1
File comments: 11
Uploads: 2
Originally Posted by coolmodi
Why don't you just make the UI behave like a real calculator by adding brackets and just showing whatever you enter, pressing = will then solve it, as long as the syntax was correct. Would be much more useful that way if you could just enter stuff like (x+y)*(z-w).
I would like to have that kind of functionality but I find myself running into issues when trying to handle order of operations. My mind quickly starts thinking parse trees and runs away. Maybe I'm overthinking what I would have to do but I currently cannot think of a simple way of going about handling the order and depth.

Originally Posted by coolmodi
Edit: You also haven't defined LAM2 used on line 146, that throws an error. You need:
Lua Code:
  1. local LAM2 = LibStub("LibAddonMenu-2.0")
I wasn't getting an error for this. Thank you for noticing and letting me know.

Originally Posted by coolmodi
Code:
font="$(BOLD_FONT)|30|soft-shadow-thin"
verticalAlignment="CENTER"
Thanks a ton for that information. I was trying to find ways to do that but was not coming up successful. The only reason I had the word button on the buttons was to center the numbers. I thought: "Well, it's a solution". After looking at the link you provided along with what you said, it now all seems obvious.

I also noticed that I could probably just call something like:
Lua Code:
  1. CalcHandleMultipleEntryOperator()
Then I would be able to eliminate a few steps that are not needed. I also started to notice that some boolean values I used for checks were not needed because I could just if(function) == true instead of setting a value for what the function returns then checking the value. But its all a learning experience.

I have no experience with XML and very little with LUA. I started this to get a feel for what can be accomplished. And maybe rushed it a little so I could release the UI before my classes started back. School and work tend to suck up all my fun time.

I really value the feedback and will be uploading the removal of the ugly "button" words and adding the definition of LAM2
Report comment to moderator  
Reply With Quote
Unread 01/20/16, 10:49 AM  
coolmodi
AddOn Author - Click to view AddOns

Forum posts: 47
File comments: 56
Uploads: 3
Why don't you just make the UI behave like a real calculator by adding brackets and just showing whatever you enter, pressing = will then solve it, as long as the syntax was correct. Would be much more useful that way if you could just enter stuff like (x+y)*(z-w).

Edit: You also haven't defined LAM2 used on line 146, that throws an error. You need:
Lua Code:
  1. local LAM2 = LibStub("LibAddonMenu-2.0")

Another thing:

Lua Code:
  1. function CalcHandleMultipleEntryOperator(value, valueTwo, operator)
  2.    
  3.    [snip]
  4.  
  5.     --I feel like since this stuff is all in the same file i dont
  6.     -- need to pass anything in or return anything
  7.     --so this is prob pointless, but it works.. so okay
  8.    return value
  9. end

If your function is used to fill a value, like you do here

Lua Code:
  1. value =  CalcHandleMultipleEntryOperator(value, valueTwo, operator)

you need to return something, whatever you return is what "value" is set to. So it's not pointless

Edit: Oh wait, value is defined localy for the whole file, but then you can just call the funtion and really don't need the return.

Lua Code:
  1. CalcHandleMultipleEntryOperator(value, valueTwo, operator)
instead of
Lua Code:
  1. value =  CalcHandleMultipleEntryOperator(value, valueTwo, operator)

Edit: And the last thing for now
Why not remove the "Button" from all buttons and only leave the number or symbol? If you don't want them to be at the top of the button you can center them by adding
verticalAlignment="CENTER"
and then make it bigger by using a bigger font, you can use any size you want by changing the number, e.g.
Code:
font="$(BOLD_FONT)|30|soft-shadow-thin"
Last edited by coolmodi : 01/20/16 at 11:26 AM.
Report comment to moderator  
Reply With Quote
Unread 08/14/14, 02:21 PM  
zeroIndex
AddOn Author - Click to view AddOns

Forum posts: 1
File comments: 11
Uploads: 2
Originally Posted by DeanGrey
Could you expand the description to mention what its limits are a bit more? Is it addition or is there multiplication, subtraction and division as well? Is there support for decimals?
Thank you for the input. I have updated the description in hopes to help clarify things up a bit. I also posted a picture of how it works. I updated the addon because the input of decimals was not working however the output was fine. I missed that :/
Report comment to moderator  
Reply With Quote
Unread 08/14/14, 07:26 AM  
DeanGrey
 
DeanGrey's Avatar
AddOn Author - Click to view AddOns

Forum posts: 16
File comments: 73
Uploads: 3
Could you expand the description to mention what its limits are a bit more? Is it addition or is there multiplication, subtraction and division as well? Is there support for decimals?
Report comment to moderator  
Reply With Quote
Post A Reply



Category Jump: