I have a GUI textbox, and I want the ability to detect if the text that was input was a number, or a letter. How would I do this? I know it has to involve a '~=' and a loop to check it.
You can check by using the 'type' method, the type
method will identify the identifier
type of what it is, for example, if you were to use the following code;
local str = "I'm a sting!" print(type(str)) --Output: string
As you'll see, after firing that code, it has printed string
in the Output because str
is a string
identifier, this same thing will happen for Numbers
and Booleans
aswell;
local bool = true print(type(bool)) --Output: boolean local num = 1 print(type(num))
So, to answer your question, this can also be used in if then end
statements to identify certain identifiers
, like for example;
local identifier = "string" --A string :o if type(identifier) == "number" then --If 'identifier' is a 'number' then --Code return identifier --Returns the number elseif type(identifier) == "string" then --Elseif 'identifier' is a 'string' then --Code return #identifier --Returns the number of Characters in a string elseif type(identifier) == "table" then --Surprised? it even works with 'table''s! :D --Code return #identifier --Returns the number of string/numbers/ect. in a table end
Hope this helped!