Vid_eo
|
  |
| Joined: 30 Jul 2013 |
| Total Posts: 2580 |
|
|
| 09 Feb 2017 03:17 PM |
Say I wanted to make a calculator.
I set a specific value (like a number value) to the operation when the + button is clicked (in this case the operation is "+") and then when I press the equal number, it adds two numbers, like 1 and 1.
Whenever I try this with a string value, it only makes a GUI show "1+1". |
|
|
| Report Abuse |
|
|
|
| 09 Feb 2017 03:18 PM |
tostring(result)
NOW GATHER, UNDER THE NAME OF TEAM ROCKET! |
|
|
| Report Abuse |
|
|
|
| 09 Feb 2017 03:19 PM |
local signs = { ["+"] = function(a,b) return a+b end }
print(signs["+"](2,3)) |
|
|
| Report Abuse |
|
|
|
| 09 Feb 2017 03:20 PM |
and you index it by the operation so for example
local operation = something local result = signs[ operation ](val1, val2.....) --other values will be ignored if too many box.Text = result
|
|
|
| Report Abuse |
|
|
|
| 09 Feb 2017 03:21 PM |
Okay so there is two things...
One is Strings, the other is Numbers.
So strings are like sentences. They are just words and have no numerical value. Despite that the word is "4", its not a number. Its a string. To turn it into a useable, addable number you have to use tonumber() command.
local String = "4" --string number local Number = tonumber(4) --gives useable number
|
|
|
| Report Abuse |
|
|
|
| 09 Feb 2017 03:21 PM |
| The wunder wolfe has ninja'ed me. |
|
|
| Report Abuse |
|
|
|
| 09 Feb 2017 03:22 PM |
| it does make a lot of functions but it makes you avoid things like many if statements or loadstring if you want to go the if statement route: local result if operation ## ### then result = val1+val2 end box.Text = result |
|
|
| Report Abuse |
|
|
Vid_eo
|
  |
| Joined: 30 Jul 2013 |
| Total Posts: 2580 |
|
| |
|
Vid_eo
|
  |
| Joined: 30 Jul 2013 |
| Total Posts: 2580 |
|
| |
|
|
| 09 Feb 2017 03:34 PM |
string manipulation? in other words, string "3+7" will evaluate to 10? do you only need addition, or other operations too?
|
|
|
| Report Abuse |
|
|
|
| 09 Feb 2017 04:29 PM |
| i already told you how to do it ... |
|
|
| Report Abuse |
|
|
TimeTicks
|
  |
| Joined: 27 Apr 2011 |
| Total Posts: 27115 |
|
| |
|
Vid_eo
|
  |
| Joined: 30 Jul 2013 |
| Total Posts: 2580 |
|
|
| 09 Feb 2017 05:32 PM |
| yes and i need more operations @unsubtleties |
|
|
| Report Abuse |
|
|
|
| 09 Feb 2017 06:56 PM |
| i literally gave you a solution for using multiple operations, im not even going to help anymore |
|
|
| Report Abuse |
|
|
|
| 09 Feb 2017 06:56 PM |
^ that's not string manipulation, that's a table of functions
|
|
|
| Report Abuse |
|
|
|
| 09 Feb 2017 06:58 PM |
ik but you do not need string manipulation, you can use 'if' or a table, string manipulation will over complicate it
but i guess you can do
("2+4"):gsub("(%d+)%+(%d+)",function(a,b) print(a,b) end)
but why though |
|
|
| Report Abuse |
|
|
|
| 09 Feb 2017 07:00 PM |
you're not understanding this. OP wants order of operations to be applied, not individually calling functions for each operation
TimeTicks's solution should work perfectly
|
|
|
| Report Abuse |
|
|
|
| 09 Feb 2017 08:35 PM |
| ^ Your a very salty person. |
|
|
| Report Abuse |
|
|