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: How to make sure something is a number?

Previous Thread :: Next Thread 
PsXboxWii is not online. PsXboxWii
Joined: 20 Jul 2010
Total Posts: 374
13 Apr 2012 03:50 PM
I don't want it to be letters that a player types into a TextBox.
Report Abuse
PsXboxWii is not online. PsXboxWii
Joined: 20 Jul 2010
Total Posts: 374
13 Apr 2012 03:51 PM
Bump
Report Abuse
PsXboxWii is not online. PsXboxWii
Joined: 20 Jul 2010
Total Posts: 374
13 Apr 2012 04:01 PM
BUMPPPPP!
Report Abuse
Ganondude is not online. Ganondude
Joined: 22 Jun 2007
Total Posts: 1175
13 Apr 2012 04:03 PM
You can use the gsub() string function to parse the input string and remove all non-numbers.

--

local s = TextBox.Text

s = string.gsub(s,"[^%d+]","") -- replace all non-digits with ""

--

The pattern [^%d+] represents the set of all characters that are not digits (0-9),
Report Abuse
PsXboxWii is not online. PsXboxWii
Joined: 20 Jul 2010
Total Posts: 374
13 Apr 2012 04:04 PM
D: too confusing for me... Anything easier for me?

Even if I did use that way, what if what they typed didn't have any numbers?
Report Abuse
PsXboxWii is not online. PsXboxWii
Joined: 20 Jul 2010
Total Posts: 374
13 Apr 2012 04:05 PM
Okay, if this question is easier to answer, answer this one instead:

How do you make sure something is a string?

That way I can use ~= on it.
Report Abuse
Ganondude is not online. Ganondude
Joined: 22 Jun 2007
Total Posts: 1175
13 Apr 2012 04:10 PM
If what they typed didn't have any numbers then s would simply be the empty string ("").

A TextBox's Text will always be a string.

You don't need to understand pattern captures to use this; try using this in your script:

--

local textBox = gui.TextBox -- set this to your TextBox

textBox.Text = string.gsub(textBox.Text,"[^%d+]","")

--

This will remove any non-numbers from the TextBox's Text. Then you could just check that what they entered had at least one number by comparing the text to the empty string:

--

if (textBox.Text ~= "") then
-- at least one number has been entered
end

--
Report Abuse
miz656 is not online. miz656
Joined: 19 Jul 2010
Total Posts: 15336
13 Apr 2012 04:34 PM
You can use the type function.

print(type(4)) -- number

Though in the situation might not be the best.
Report Abuse
bagwan12345 is not online. bagwan12345
Joined: 17 Dec 2009
Total Posts: 1498
13 Apr 2012 04:41 PM
@GanonDude

That would work well, but I'm pretty sure that if people were to type an equation in the TextBox, it would error.
Report Abuse
bagwan12345 is not online. bagwan12345
Joined: 17 Dec 2009
Total Posts: 1498
13 Apr 2012 05:23 PM
Correction: Expression
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