boyned12
|
  |
| Joined: 19 Jan 2009 |
| Total Posts: 766 |
|
| |
|
boyned12
|
  |
| Joined: 19 Jan 2009 |
| Total Posts: 766 |
|
| |
|
Spectrumw
|
  |
| Joined: 04 Aug 2009 |
| Total Posts: 13510 |
|
| |
|
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
|
  |
| Joined: 12 Jun 2009 |
| Total Posts: 13241 |
|
| |
|
myrco919
|
  |
| Joined: 12 Jun 2009 |
| Total Posts: 13241 |
|
| |
|
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
|
  |
| Joined: 12 Jun 2009 |
| Total Posts: 13241 |
|
| |
|
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
|
  |
| Joined: 12 Jun 2009 |
| Total Posts: 13241 |
|
| |
|
|
| 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
|
  |
| 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
|
  |
| 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
|
  |
| Joined: 04 Aug 2009 |
| Total Posts: 13510 |
|
|
| 07 Jul 2011 01:00 PM |
@boyned By the way my script works é.e |
|
|
| Report Abuse |
|
|
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
|
  |
| Joined: 04 Aug 2009 |
| Total Posts: 13510 |
|
|
| 07 Jul 2011 01:04 PM |
@Rawr Yes, but in a way shorter version. |
|
|
| Report Abuse |
|
|
RawrBot
|
  |
| Joined: 22 Aug 2008 |
| Total Posts: 832 |
|
| |
|
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 |
|
|