generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripters
Home Search
 

Re: Is there a value for something like * or +?

Previous Thread :: Next Thread 
Vid_eo is not online. 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
Snowskateer is not online. Snowskateer
Joined: 06 Dec 2011
Total Posts: 4647
09 Feb 2017 03:18 PM
tostring(result)

NOW GATHER, UNDER THE NAME OF TEAM ROCKET!
Report Abuse
Wunder_Wulfe is online. Wunder_Wulfe
Joined: 13 Sep 2016
Total Posts: 8356
09 Feb 2017 03:19 PM
local signs = {
["+"] = function(a,b) return a+b end
}

print(signs["+"](2,3))
Report Abuse
Wunder_Wulfe is online. Wunder_Wulfe
Joined: 13 Sep 2016
Total Posts: 8356
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
dudefun1234 is not online. dudefun1234
Joined: 21 Jul 2013
Total Posts: 3038
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
dudefun1234 is not online. dudefun1234
Joined: 21 Jul 2013
Total Posts: 3038
09 Feb 2017 03:21 PM
The wunder wolfe has ninja'ed me.
Report Abuse
Wunder_Wulfe is online. Wunder_Wulfe
Joined: 13 Sep 2016
Total Posts: 8356
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 is not online. Vid_eo
Joined: 30 Jul 2013
Total Posts: 2580
09 Feb 2017 03:28 PM
b1
Report Abuse
Vid_eo is not online. Vid_eo
Joined: 30 Jul 2013
Total Posts: 2580
09 Feb 2017 03:33 PM
VW4DLRv7
Report Abuse
Unsubtleties is not online. Unsubtleties
Joined: 28 Nov 2016
Total Posts: 9203
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
Wunder_Wulfe is online. Wunder_Wulfe
Joined: 13 Sep 2016
Total Posts: 8356
09 Feb 2017 04:29 PM
i already told you how to do it ...
Report Abuse
TimeTicks is not online. TimeTicks
Joined: 27 Apr 2011
Total Posts: 27115
09 Feb 2017 04:48 PM
loadstring('2+3')


Report Abuse
Vid_eo is not online. Vid_eo
Joined: 30 Jul 2013
Total Posts: 2580
09 Feb 2017 05:32 PM
yes and i need more operations @unsubtleties
Report Abuse
Wunder_Wulfe is online. Wunder_Wulfe
Joined: 13 Sep 2016
Total Posts: 8356
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
Unsubtleties is not online. Unsubtleties
Joined: 28 Nov 2016
Total Posts: 9203
09 Feb 2017 06:56 PM
^ that's not string manipulation, that's a table of functions


Report Abuse
Wunder_Wulfe is online. Wunder_Wulfe
Joined: 13 Sep 2016
Total Posts: 8356
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
Unsubtleties is not online. Unsubtleties
Joined: 28 Nov 2016
Total Posts: 9203
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
dudefun1234 is not online. dudefun1234
Joined: 21 Jul 2013
Total Posts: 3038
09 Feb 2017 08:35 PM
^ Your a very salty person.
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image