Jlobblet
|
  |
| Joined: 05 Sep 2010 |
| Total Posts: 587 |
|
|
| 11 Aug 2012 10:53 AM |
I'm guessing it's possible without the extra lines of code, but
Is it possible to have an argument in a function, which isoptional? IE you don't have to call it? Such as:
function abc(d=true) print(d) end
And it will be:
abc() --> true abc(false) -->false
Or would you need to do:
function abc(d) if d == nil then d = true end print(d) end
?
~if not ok then return end |
|
|
| Report Abuse |
|
|
miz656
|
  |
| Joined: 19 Jul 2010 |
| Total Posts: 15336 |
|
|
| 11 Aug 2012 10:56 AM |
Why don't you test this out yourself? Roblox made a studio for testing and making games you know...
|
|
|
| Report Abuse |
|
|
Jlobblet
|
  |
| Joined: 05 Sep 2010 |
| Total Posts: 587 |
|
|
| 11 Aug 2012 10:57 AM |
As I know then 2nd works, but do not know the way to set a default WITHOUT the extra line. That is the enquiry.
~if not ok then return end |
|
|
| Report Abuse |
|
|
miz656
|
  |
| Joined: 19 Jul 2010 |
| Total Posts: 15336 |
|
|
| 11 Aug 2012 11:01 AM |
function abc(d) print d == true and "yep or "no" end
|
|
|
| Report Abuse |
|
|
Jlobblet
|
  |
| Joined: 05 Sep 2010 |
| Total Posts: 587 |
|
|
| 11 Aug 2012 11:03 AM |
And operator, I kicked myself.
~if not ok then return end |
|
|
| Report Abuse |
|
|
miz656
|
  |
| Joined: 19 Jul 2010 |
| Total Posts: 15336 |
|
|
| 11 Aug 2012 11:06 AM |
| That's the beast way to do it man ^_^ |
|
|
| Report Abuse |
|
|
Jlobblet
|
  |
| Joined: 05 Sep 2010 |
| Total Posts: 587 |
|
|
| 11 Aug 2012 11:09 AM |
Adapting it to any agument, generally:
function abc(d) return (d ~= nil and "d ~= nil" or "d == nil") end
~if not ok then return end |
|
|
| Report Abuse |
|
|