Jump to content

[Help] Calculator


#Just_Me

Recommended Posts

  • Moderators
-- client side --
addCommandHandler ("multiply",
function (commandName, number1, number2)
    number1 = tonumber(number1)
    number2 = tonumber(number2)
    if number1 and number2 then
      	local result = number1 * number2
    	outputChatBox(result)
    end
end)
/multiply 5 5

CLIENTSIDE

Quote

and then i get the results by pressing Get Results

?????

Edited by IIYAMA
Link to comment
  • Moderators
local theMath = "5 * 5"
local calculate = loadstring("outputChatBox(" .. theMath .. ")")
calculate();

Without complex string manipulation. Yet it can contain all kinds of calculations, but you have to be careful because it can contain more than ONLY math. Security risks!

Is it for public or only personal use?

Edited by IIYAMA
Link to comment

that's a good idea

but i have this way:

string.gsub ("letter45", "%D", "")
-- result: 45

 

it returns the numbers only but if i entered one of these methods: (+ - * /)

it removes them too ..

 

so .. i made this function .. i think it's good now to use it like this way ..

function filterMath (text)
    local result = string.gsub (text, "[A-Za-z-[%]-{%}%'<>?:;!@#$^&()=]", "")
    local equation = loadstring ("return " .. result)
    if (equation) then
        return equation ()
    else
        return "No Results"
    end
end

 

Edited by #Just_Me
  • Like 1
Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...