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: If a string is a String or a Number

Previous Thread :: Next Thread 
tehepicford is not online. tehepicford
Joined: 26 Aug 2011
Total Posts: 1486
18 May 2012 02:21 PM
^ Any ideas?
Report Abuse
CloneTrooper1019 is not online. CloneTrooper1019
Joined: 19 Jan 2009
Total Posts: 6227
18 May 2012 02:23 PM
To detect its type you can use this

type()

example

print(type("LOL"))
Output: string
Report Abuse
crazyman32 is not online. crazyman32
Joined: 13 Apr 2008
Total Posts: 18027
18 May 2012 02:23 PM
local whatever = "Test"

if (type(whatever) == "string") then
-- String
elseif (type(whatever == "number") then
-- Number
end


I believe there is: string, number, boolean, function, table, userdata. Maybe more
Report Abuse
tehepicford is not online. tehepicford
Joined: 26 Aug 2011
Total Posts: 1486
18 May 2012 02:24 PM
How to use it in a If statement?
Report Abuse
tehepicford is not online. tehepicford
Joined: 26 Aug 2011
Total Posts: 1486
18 May 2012 02:24 PM
Lol, Thanks clone. But not enough info.
But thanks crazy ;P
Report Abuse
crazyman32 is not online. crazyman32
Joined: 13 Apr 2008
Total Posts: 18027
18 May 2012 02:25 PM
Ohhhh I'm so telepathic
Report Abuse
juriaan is not online. juriaan
Joined: 25 Nov 2008
Total Posts: 939
18 May 2012 02:26 PM
@Crazyman32

The list of Type :

"number", "string", "boolean", "table", "function", "thread", and "userdata".

Report Abuse
crazyman32 is not online. crazyman32
Joined: 13 Apr 2008
Total Posts: 18027
18 May 2012 02:26 PM
Gah, just missed thread
Report Abuse
tehepicford is not online. tehepicford
Joined: 26 Aug 2011
Total Posts: 1486
18 May 2012 02:30 PM
Lol.
Report Abuse
tehepicford is not online. tehepicford
Joined: 26 Aug 2011
Total Posts: 1486
18 May 2012 02:30 PM
Well thanks all, It really helps me with my plugin =D
Report Abuse
tehepicford is not online. tehepicford
Joined: 26 Aug 2011
Total Posts: 1486
18 May 2012 02:39 PM
Problem, Im using it for a text box on my plugin.

But.
Even if you input a number to it Roblox calls it as a string.
But if I use to number and its a string it won't work, I don't think.

Any ideas?
Report Abuse
crazyman32 is not online. crazyman32
Joined: 13 Apr 2008
Total Posts: 18027
18 May 2012 02:39 PM
local input = tonumber(TEXTBOX.Text)
if (input) then
-- It's a number
else
-- Not a number
end
Report Abuse
rayoma is not online. rayoma
Joined: 13 Nov 2009
Total Posts: 1911
18 May 2012 03:21 PM
@clone
That would always give you a string in this situation. How I would always do this is simple,

    print(not not tonumber(string));--will be true if it's a number, false if it isn't
Report Abuse
ElectricBlaze is not online. ElectricBlaze
Joined: 18 Jul 2011
Total Posts: 22930
18 May 2012 03:26 PM
@rayoma - No, that would be the same as:

    print(tonumber(string))

You said "not" twice, so you inforced a double negative - print the opposite of the opposite of tonumber(string), or print tonunumer(string). Just like saying, "I don't not want to go the doctor's" is like saying "I want to go to the doctor's".
Report Abuse
epicfail22 is not online. epicfail22
Joined: 25 Sep 2009
Total Posts: 3739
18 May 2012 03:28 PM
^ What he said.
Report Abuse
rayoma is not online. rayoma
Joined: 13 Nov 2009
Total Posts: 1911
18 May 2012 03:30 PM
@electric
Using double nots is the most common way to change something into a boolean. Your script would either give a number or nil, mine would give true or false. There is a difference.
Report Abuse
ElectricBlaze is not online. ElectricBlaze
Joined: 18 Jul 2011
Total Posts: 22930
18 May 2012 03:33 PM
@rayoma - If you read my post thoroughly, you'd notice I wasn't correcting you, simply making a comment.
Report Abuse
rayoma is not online. rayoma
Joined: 13 Nov 2009
Total Posts: 1911
18 May 2012 03:34 PM
@electric - If you read my post thoroughly, you'd notice I wasn't correcting you, simply making a comment.
Report Abuse
ElectricBlaze is not online. ElectricBlaze
Joined: 18 Jul 2011
Total Posts: 22930
18 May 2012 03:58 PM
> Your script would either give a number or nil, mine would give true or false. There is a difference.

wutnao?
Report Abuse
rayoma is not online. rayoma
Joined: 13 Nov 2009
Total Posts: 1911
18 May 2012 04:03 PM
> No, that would be the same as

-------------
> Just like saying, "I don't not want to go the doctor's" is like saying "I want to go to the doctor's".


-------------
wutnao?
Report Abuse
ElectricBlaze is not online. ElectricBlaze
Joined: 18 Jul 2011
Total Posts: 22930
18 May 2012 04:05 PM
Heh, true. If I didn't say "no", it wouldn't be a correction though. :P
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