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 » Scripting Helpers
Home Search
 

Re: Calcualtor help..

Previous Thread :: Next Thread 
crouton04 is not online. crouton04
Joined: 07 Jul 2010
Total Posts: 4459
11 Dec 2012 04:31 PM
This code is supposed to get num1, num2, and the sign. However, it doesn't..


script.Parent.MouseButton1Click:connect(function ()
print("Math")
num1 = script.Parent.Parent.Math.Text:sub(1)
num2 = script.Parent.Parent.Math.Text:sub(3)
sign = script.Parent.Parent.Math.Text:sub(2)
if sign == "+" then
script.Parent.Parent.Math.Text = num1 + num2
end
end)

Question, does sub remove the letter? Or remove things around letter?
Report Abuse
AgentFirefox is not online. AgentFirefox
Top 100 Poster
Joined: 20 Jun 2008
Total Posts: 22404
11 Dec 2012 04:33 PM
Use sub(1, 1), sub(2, 2), and sub(3, 3). When you supply one argument, it captures the substring from your index supplied all the way to the end of the string.

To be honest, string.match would be a better choice for this. Would you like to see how to use it here?
Report Abuse
BlueTaslem is not online. BlueTaslem
Joined: 11 May 2008
Total Posts: 11060
11 Dec 2012 04:33 PM
sub obtains a substring.

For instance,

local str = "abcdefgh"
print(str:sub(2,4))
-- bcd

The 2nd through 4th characters.
Report Abuse
crouton04 is not online. crouton04
Joined: 07 Jul 2010
Total Posts: 4459
11 Dec 2012 04:36 PM
Ok, please do use it.
Report Abuse
crouton04 is not online. crouton04
Joined: 07 Jul 2010
Total Posts: 4459
11 Dec 2012 04:36 PM
Ok, please do use it.
Report Abuse
AgentFirefox is not online. AgentFirefox
Top 100 Poster
Joined: 20 Jun 2008
Total Posts: 22404
11 Dec 2012 04:41 PM
script.Parent.MouseButton1Click:connect(function ()
print("Math")
local num1, sign, num2 = script.Parent.Parent.Math.Text:match("(%d+)%s*(.)%s*(%d+)")
num1, num2 = tonumber(num1) or 0, tonumber(num2) or 0
if sign == "+" then
script.Parent.Parent.Math.Text = num1 + num2
end
end)


%d+ captures all digits, with at least one required, takign the longest sequence of digits (0-9).
. is any character. This will be your sign.
%s is whitespace. * denotes optional. Since neither of the %s* are in parenthesis, we do not capture the whitespace.
Report Abuse
crouton04 is not online. crouton04
Joined: 07 Jul 2010
Total Posts: 4459
11 Dec 2012 06:43 PM
THANKS!!!

I only need help with one more thing.. How would I get the precentage of a number to another number?? Would it be..

100%200

>%50

or would I use math?

100/200

>>.50
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripting Helpers
   
 
   
  • 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