Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

What is the best way to make an advanced calculator?

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.

2 comments

0

Yeah.... I guess everyone is having a hard time with this one.

1

questions don't get answered within ten minutes.

1 answer

✓ Accepted answer

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)

1 comment

0

Helps! Thanks, I was looking for something like this.

This discussion is preserved as it was. New answers, comments, and votes are closed.