#Just_Me Posted January 17, 2017 Share Posted January 17, 2017 (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 January 17, 2017 by #Just_Me Link to comment
Moderators IIYAMA Posted January 17, 2017 Moderators Share Posted January 17, 2017 (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 January 17, 2017 by IIYAMA Link to comment
#Just_Me Posted January 17, 2017 Author Share Posted January 17, 2017 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 Link to comment
Moderators IIYAMA Posted January 17, 2017 Moderators Share Posted January 17, 2017 (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 January 17, 2017 by IIYAMA Link to comment
Mr.Loki Posted January 18, 2017 Share Posted January 18, 2017 You can also do this with the runcode resource. /crun 5 * 5 executed command: 5 * 5 Command results: 25 [number] Link to comment
#Just_Me Posted January 18, 2017 Author Share Posted January 18, 2017 IIYAMA no it's for public .. yes it's more than math i know that ... it can run codes and a lot of stuff .. it needs some changes in it to be good to use .. thank you Link to comment
Moderators IIYAMA Posted January 18, 2017 Moderators Share Posted January 18, 2017 Here you have an example how to filter with specific characters: http://stackoverflow.com/questions/27321103/limitting-character-input-to-specific-characters If players can't use letters, most of the danger has been solved. No letters = no functions. Link to comment
#Just_Me Posted January 19, 2017 Author Share Posted January 19, 2017 (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 January 19, 2017 by #Just_Me 1 Link to comment
Moderators IIYAMA Posted January 19, 2017 Moderators Share Posted January 19, 2017 nice! Link to comment
#Just_Me Posted January 19, 2017 Author Share Posted January 19, 2017 Thank you for your help. 1 Link to comment
Moderators IIYAMA Posted January 19, 2017 Moderators Share Posted January 19, 2017 np. Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now