PDA

View Full Version : /calc command



Oberoten
February 26th, 2009, 16:47
Can we have something like this? Or how hard would it be to implement a command to do calculations on the fly?

/calc 10 * 1.25^3

/calc C * 1.8 + 30


Would be very very useful.

- Obe

ErsatzPyre
February 26th, 2009, 19:47
I usually just alt+tab win calc, but that would be quite a nice replacement indeed! It can't be very difficult to do, I would think.

Or is there a way to make an extension for a calc like that?

Tenian
February 26th, 2009, 19:52
I'm pretty sure you can register your own slash handler. I know the 4E_JPG has one that handles whispers (/w) so players can whisper to each other in addition to the GM.

Building a fully functional /calc command might get tricky depending on the level of complexity you want to incorporate, particularly the processing of ()'s might not be fun.

Oberoten
February 27th, 2009, 06:15
Well some progress at the least. I have modified the /die command so it can now do the four basic ones and round down. This is ... quite useful.

- Obe

joshuha
February 27th, 2009, 12:48
Could you maybe build a parser than could run the real LUA math commands but from within FG? Then the syntax would be different (not as compact) but things like nesting would work.

Oberoten
March 2nd, 2009, 08:20
Well... I think I am going to scrap the first idea for this one.

No /calc command. Instead I am building a panel that has the most common tasks in it.

(( Square root (gravity * 2 * distance) for falling speed among other things. ))

- Obe

Ikael
March 2nd, 2009, 18:16
hi, I have actually done small calculator script that parses given string and handels +, -, *, /, ^ and sqrt operations, it also understands ()'s . The only problem is that it doesn't understand float numbers and that's why it's not accurate with / and sqrt operations. The code itself is not pretty or perfectly "lua-certified" and fits in arounds 200 rows but for my own purposes it has served well. If you still need I could share the script.

Oberoten
March 2nd, 2009, 21:25
It'd be VERY welcome. :)

- Obe

Ikael
March 3rd, 2009, 16:07
I sent you email

Bidmaron
March 4th, 2009, 02:03
Any thought to making this an extension when you finish it, Obe?

Oberoten
March 4th, 2009, 07:18
It probably will be, yes. In a few days time when I am off work again. (( Nine days in a row now of 11-22 workshifts. URGH))

- Obe

EugeneZ
March 5th, 2009, 04:02
Well, I just made one in about twenty minutes that supports +,-,*,/, parens, and decimals in both input and output, and even labels.

Warning, this is my first ever lua script and no doubt sucks horribly...

Tested in 4e_jpg and d20, but it's so simple it should work in anything, really.

To use, just type /calc and then a math problem. You can also add a label at the end and the program will automatically round down and spit out the answer as a "draggable" number. So


/calc 3/2

displays 1.5


/calc 3/2 Gems

displays a DRAGGABLE "1 Gems".

It can be downloaded here: (I tried to attach but it was invalid... heh.)

https://www.eugenez.net/downloads/ezcalc.ext

I only tested some basic stuff in it, it's very possible there are a number of bugs. Report them here and I'll fix them...

Ikael
March 9th, 2009, 12:40
EugeneZ, that's a very neath code :) Thou, there are some bugs with ()'s for example in handling inner ()'s.

I also did some studing in making extansions and created extension from my calcualtor script (attached in this message). This updated version handles now decimal numbers, ()'s, +, -, ^, *, / and Sqrt operations. The result is shown as precise decimal number and also as a draggable number rounded to nearest end. It also allows user to create constants to CampaignRegistry, for example G = 9.81 or pi = 3.14, which may be used in the calcualtor.

Hopefully it's helpful for somebody

Oberoten
March 9th, 2009, 13:17
This is actually exactly what I was hoping for when I started out. :) Good Job. REALLY good job.

- Obe

Oberoten
March 10th, 2009, 00:54
It works even better than I thought it would. :)

I'll take a poke at it and try to understand how it works... this is a LOT more advanced than what I tried to create.

*hmmmm* I wonder if it could be incorporated into the /die command ...

/die 1d10*15 Goldpieces?

- Obe

SpudmanWP
September 19th, 2010, 17:19
EugeneZ, that's a very neath code :) Thou, there are some bugs with ()'s for example in handling inner ()'s.

I also did some studing in making extansions and created extension from my calcualtor script (attached in this message). This updated version handles now decimal numbers, ()'s, +, -, ^, *, / and Sqrt operations. The result is shown as precise decimal number and also as a draggable number rounded to nearest end. It also allows user to create constants to CampaignRegistry, for example G = 9.81 or pi = 3.14, which may be used in the calcualtor.

Hopefully it's helpful for somebody

Any chance of getting it parse dice rolls so we can do something like 3d6*1.25?

Ikael
October 4th, 2010, 20:31
for the die notation request I updated the calculator script. Now the calculation expression may contain any die notations: 3d6, d8 or d100 etc. and it will automatically make random number for each such a die notation before calculating it. Die results are printed to the console. The updated version can be downloaded from FGWiki. Direct link (https://oberoten.dyndns.org/fgwiki/images/5/54/Calculator.ext)