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
|
  |
| Joined: 20 Jul 2010 |
| Total Posts: 374 |
|
| |
|
PsXboxWii
|
  |
| Joined: 20 Jul 2010 |
| Total Posts: 374 |
|
| |
|
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
|
  |
| 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
|
  |
| 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
|
  |
| 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
|
  |
| 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 |
|
|
|
| 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 |
|
|
| |
|