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: Does nil count as a bool?

Previous Thread :: Next Thread 
boyned12 is not online. boyned12
Joined: 19 Jan 2009
Total Posts: 766
07 Jul 2011 12:47 PM
Does it?
Report Abuse
boyned12 is not online. boyned12
Joined: 19 Jan 2009
Total Posts: 766
07 Jul 2011 12:48 PM
52 views and no help
Report Abuse
Spectrumw is not online. Spectrumw
Joined: 04 Aug 2009
Total Posts: 13510
07 Jul 2011 12:48 PM
Yes, it count as false.
Report Abuse
boyned12 is not online. boyned12
Joined: 19 Jan 2009
Total Posts: 766
07 Jul 2011 12:50 PM
So I could just do this?

function Test()
if workspace.Pie == false then return "sorry" end
if workspace.Pie == true then return "yes" end
end

print(Test())

Pretending Test isn't there,would it print sorry?
Report Abuse
myrco919 is not online. myrco919
Joined: 12 Jun 2009
Total Posts: 13241
07 Jul 2011 12:50 PM
[ Content Deleted ]
Report Abuse
myrco919 is not online. myrco919
Joined: 12 Jun 2009
Total Posts: 13241
07 Jul 2011 12:51 PM
[ Content Deleted ]
Report Abuse
boyned12 is not online. boyned12
Joined: 19 Jan 2009
Total Posts: 766
07 Jul 2011 12:51 PM
I mean Pretending Pie isn't there XD
Report Abuse
myrco919 is not online. myrco919
Joined: 12 Jun 2009
Total Posts: 13241
07 Jul 2011 12:51 PM
[ Content Deleted ]
Report Abuse
boyned12 is not online. boyned12
Joined: 19 Jan 2009
Total Posts: 766
07 Jul 2011 12:53 PM
I cant because I had to end the if statement with return because return stops running the scope after it is called.
Report Abuse
myrco919 is not online. myrco919
Joined: 12 Jun 2009
Total Posts: 13241
07 Jul 2011 12:54 PM
[ Content Deleted ]
Report Abuse
crazypotato4 is not online. crazypotato4
Joined: 22 Feb 2010
Total Posts: 20000
07 Jul 2011 12:54 PM
nil is not a boolean, it is its own type of value.

And that would error if Pie isn't there. The admins do stupid stuff with metatables to make sure it errors.
Report Abuse
Spectrumw is not online. Spectrumw
Joined: 04 Aug 2009
Total Posts: 13510
07 Jul 2011 12:55 PM
function Test()
Is = Workspace:findFirstChild("Pie") and "yes" or "sorry"
return Is
end

print(Test())

That should do it I think, let me check :3
Report Abuse
Spectrumw is not online. Spectrumw
Joined: 04 Aug 2009
Total Posts: 13510
07 Jul 2011 12:59 PM
@crazy
Technically nil isn't the same as a boolean, but in Lua everything but nil and false is true, so we can consider nil as false.
Report Abuse
Spectrumw is not online. Spectrumw
Joined: 04 Aug 2009
Total Posts: 13510
07 Jul 2011 01:00 PM
@boyned
By the way my script works é.e
Report Abuse
RawrBot is not online. RawrBot
Joined: 22 Aug 2008
Total Posts: 832
07 Jul 2011 01:02 PM
function Test()
Is = Workspace:findFirstChild("Pie") and "yes" or "sorry"
return Is
end

print(Test())

Wow I didn't know you can add "and" to a variable.

Is the variable:
Is = Workspace:findFirstChild("Pie") and "yes" or "sorry"

the same thing as:
if Workspace:findFirstChild("Pie") then
return "yes"
else
return "sorry"
end
Report Abuse
Spectrumw is not online. Spectrumw
Joined: 04 Aug 2009
Total Posts: 13510
07 Jul 2011 01:04 PM
@Rawr
Yes, but in a way shorter version.
Report Abuse
RawrBot is not online. RawrBot
Joined: 22 Aug 2008
Total Posts: 832
07 Jul 2011 01:05 PM
Ah I see.
Report Abuse
RawrBot is not online. RawrBot
Joined: 22 Aug 2008
Total Posts: 832
07 Jul 2011 01:10 PM
@boyned

You can also try

if -blah- ~= nil then
-stuff-
else
-stuff-
end
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