Jump to content

[Help] Calculator


#Just_Me

Recommended Posts

Posted (edited)

hello guys,

How to multiplying two numbers within a single text. ?

for example: 5 * 5 = 25

like in one Edit only, and then i get the results by pressing Get Results

and the equation Solved ?

help please

Edited by #Just_Me
  • Moderators
Posted (edited)
-- 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
Posted

yes thanks ..

your way i already know it but .. what i need is

to do it in Edit .. like i'm typing 5 * 5

in the edit and there is a button to get the results of this equation i entered

but thanks .. this function helped me .. string.match

  • Moderators
Posted (edited)
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
Posted (edited)

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

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...