Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

What is the best way to make an advanced calculator?

Asked by 8 years ago

I AM NOT ASKING FOR A SCRIPT!

So you have option one which is using loadstring(), I really hate turning on loadstring so I don't want to use this method at all.

And the other option would be scanning the whole string people inserted in the calculator and using a lot of functions to calculate it. Which is possible, but a real mind teaser.

Or is there any other way to get the answer real quick?

And no, don't say something like: "Use print!" Because I want it to show up on a TextLabel.

And no, don't say something like: "Use tonumber()" Since that will just return nil if you do something like this: tonumber("4+4") -- Returns nil.

So I am basically asking: "What is the best/fastest way to calculate a string (without using loadstring() )"

Sorry for my horrible grammar/spelling, I am not English and I've got serious problems with the English tongue.

0
Yeah.... I guess everyone is having a hard time with this one. manchester1002 57 — 8y
1
questions don't get answered within ten minutes. theCJarmy7 1293 — 8y

1 answer

Log in to vote
1
Answered by 8 years ago

Option 1: This is kind of cheating the system, but you can use the Yueliang, which is basically a lua parser written in lua. If you want to see an implementation of it, you can look at the LoadString script in the EISS MainModule by Sceleratis.

Option 2: You can use the math.js API, if you are fine with using HttpService. Here's an example from a calculator script I created a while ago, where args[1] is the equation you want to solve:

local solution = game.HttpService:GetAsync("http://api.mathjs.org/v1/?expr=" .. game.HttpService:UrlEncode(args[1], false))

If you want to try it: http://api.mathjs.org/v1/?expr=2*(7-3)

0
Helps! Thanks, I was looking for something like this. manchester1002 57 — 8y
Ad

Answer this question